MySQL 5.7 在初始安装后(CentOS7 操作系统)会生成随机初始密码,并在 /var/log/mysqld.log 中有记录,可以通过 cat 命令查看,找 password 关键字
mysql账号权限添加:
mysql -uroot -pmysql>insert into mysql.user(Host,User,Password) values('%', 'userrw', password('userrw'));
mysql>flush privileges;
mysql>grant all on *.* to 'userrw'@'%' identified by 'userrw'; #赋予全部权限
mysql>grant select,insert,update,delete,create,drop,index,alter,grant,references,reload,shutdown,process,file on *.* to 'userrw'@'%' identified by 'userrw';
mysql>flush privileges;
#mysql 5.7以上版本添加mysql.user账号方法(password字段改为了authentication_string):
CREATE USER 'user'@'localhost' IDENTIFIED BY 'userrw';
CREATE USER 'userro'@'localhost' IDENTIFIED BY 'userro';
grant all privileges on db.* to 'userrw'@'localhost';
grant all privileges on db.* to 'userro'@'localhost';
mysql非常有用的常用操作:
a、导出数据库(没有数据)
mysqldump -uroot -p123456 --opt --add-drop-table --add-drop-database -d -B db >db.nodata.sql //-d no data;
mysqldump -uroot -p123456 --opt --add-drop-table --add-drop-database -B db >db.sql //struct and data
b、查询数据库中记录不为空的表
use information_schema;
select * from TABLES where TABLE_ROWS>0 AND TABLE_SCHEMA='db';
mysqldump -uroot -p123456 db version >db-version.sql //导出db数据库version表的结构和数据
d、mysql跨库查询(连库查询)
select subscriber.username,subscriber.password, member.email from db.subscriber,db2.member where subscriber.username=member.id and member.book_id='193' limit 20;
select subscriber.username,subscriber.password, member.email,member.book_id from db.subscriber,db2.member where subscriber.username=member.id and member.book_id='193';