MacOs,修改root用户密码
mysql版本:5.7.18
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| //先暂停服务 mysql.server stop
//启动安全模式 mysqld_safe --user=mysql --skip-grant-tables
//进入mysql mysql -u root mysql
//设置密码 SET PASSWORD FOR 'root'@'localhost' = PASSWORD('新密码');
//将变更刷入内存。该步骤我没有执行,也生效了 FLUSH PRIVILEGES;
//退出 \q
//重新启动服务 mysql.server start
|
数据库备份、还原
备份某库
1 2 3 4
| mysqldump -u用户名 -p密码 -h主机 数据库 a -w “sql条件” –lock-all-tables > 路径
mysqldump -uroot -p1234 dbname a –where “tag='88′” –no-create-info> c:\a.sql mysqldump -u root -p game > /tmp/game_backup.sql
|
备份某几个库
1
| mysqldump -u root -p game game2 > /tmp/game_backup.sql
|
备份所有库
1
| mysqldump -u root -p --all-databases > /tmp/all_backup.sql
|
还原数据
1
| mysql -u root -p game < /tmp/game_backup.sql
|
跨主机同步
1 2
| mysqldump --host=host1 --opt sourceDb| mysql --host=host2 -C targetDb
|
创建用户
1 2 3 4 5 6 7
| CREATE USER username IDENTIFIED BY 'password';
CREATE USER username@localhost IDENTIFIED BY 'password';
CREATE USER username@'%' IDENTIFIED BY 'password';
|
授权
1 2 3 4
| GRANT ALL PRIVILEGES ON *.* TO user@localhost IDENTIFIED BY 'password';
GRANT select,insert ON *.* TO test1@'%' IDENTIFIED BY 'password';
|
查看用户拥有的权限
查看用户
1
| select host, user from mysql.user;
|
创建库
删除库