Mysql 安装-操作-备份

时间:2023-03-09 06:33:18
Mysql 安装-操作-备份
lower_case_table_names = 0 

Mysql 5.7 安装windows

1.配置mysql的path->系统属性->环境变量-path添加最后

2.配置目录和主从

[mysqld]
port = 3306
basedir=C:\Users\Administrator\Desktop\mysql-5.7.15-winx64\
datadir=C:\Users\Administrator\Desktop\mysql-5.7.15-winx64\data
max_connections=200
character-set-server=utf8

default-storage-engine=INNODB
#skip-grant-tables
max_allowed_packet = 16M
skip-name-resolve
lower_case_table_names=1

server-id = 1
log-bin=mysql-bin
binlog_format=mixed
expire_logs_days = 10

3.安装启动服务

mysqld install

4.初始化

mysqld --initialize --user=mysql --console

mysqld --initialize-insecure --user=mysql

mysqld --initialize
在data目录会生成系统用户表还有root用户的初始密码,密码在一个以电脑主机名命名的err文件中:

5.重设密码

启用#skip-grant-tables=1 重启#net restart mysqld

update mysql.user user set authentication_string = password('Test@123'), password_expired = 'N', password_last_changed = now() where user = 'root';

grant all privileges on *.* to root@'localhost' identified by "Test@123" with grant option;
grant all privileges on *.* to root@'127.0.0.1' identified by "Test@123" with grant option;
GRANT REPLICATION SLAVE ON *.* TO 'replication'@'%' IDENTIFIED BY 'replication';

Mysql安装
yum -y install mysql-server mysql mysql-devel #通过默认源版本5.1.73
http://dev.mysql.com/downloads/repo/yum/ #通过源安装5.5-5.7版本
================================================================

创建用户:
CREATE USER 'jacky'@'localhost' identified BY 'mypass';
GRANT SELECT ,UPDATE ON *.* TO 'testUser'@'localhost' identified BY 'testpwd';
INSERT INTO mysql.user(host,user,password) VALUES ('localhost','customer1',password('customer1'))
*identified with只能在MYSQL5.5.7及以上版本使用,identified with和identified by是互斥的
*CREATE USER语句的操作会被记录到服务器日志文件或者操作历史文件中 cat ~/.mysql_history
*查出哈希值 SELECT password('mypass'); 再使用 CREATE user 'tom'@'localhost' identified BY password 'B292FED686394CC81F802198C941D43EF0E4FB62'; 再赋值

赋予权限
grant all privileges on *.* to root@'(localhost或192.168.1.1或%)' identified by "password" with grant option;
flush privileges;
show grants;

回收权限
revoke delete on *.* from 'root'@'localhost';
REVOKE INSERT ON *.* FROM 'grantUser'@'localhost';

查看用户
select host,user,password from user; 重命名:rename user 'jack'@'%' to 'jim'@'%';

删除用户
drop user 'root'@'localhost'; 或 DELETE FROM mysql.user WHERE `Host`='localhost' and `User`='testUser'

修改密码
SET PASSWORD=PASSWORD("123456")
SET PASSWORD FOR 'root'@'localhost' = PASSWORD('123456');
mysqladmin -uroot -p123456 password 1234abcd
update user set PASSWORD = PASSWORD('1234abcd') where user = 'root';
grant USAGE ON *testUser*TO 'localhost' identified BY '123456';

找回root密码
mysqld_safe --skip-grant-tables user=mysql
/etc/init.d/mysql start-mysqld --skip-grant-tables

基础查看操作
show databases; show tables; show columns from 表 ; desc 表; show create table 表

删除整个表数据
truncate table 表名 或delete from 表名
*效率上truncate比delete快,但truncate删除后不记录mysql日志,不可以恢复数据。

删除某条表数据
delete from ofUser where username='admin';
插入某条表数据
insert into ofUser (username,plainPassword,creationDate,modificationDate) values('admin','admin','1464292787204','1464292787204');
================================================================

命令行下具体用法如下:

mysqldump -u用戶名 -p密码 -d 数据库名 表名 > 脚本名;
导出整个数据库结构和数据
mysqldump -h localhost -uroot -p123456 database > dump.sql
导出单个数据表结构和数据
mysqldump -h localhost -uroot -p123456 database table > dump.sql
导出整个数据库结构(不包含数据)
mysqldump -h localhost -uroot -p123456 -d database > dump.sql
导出单个数据表结构(不包含数据)
mysqldump -h localhost -uroot -p123456 -d database table > dump.sql