rpm -Uvh http://repo.mysql.com//mysql57-community-release-el7-7.noarch.rpm
yum -y install mysql-community-server
systemctl enable mysqld
systemctl start mysqld
systemctl status mysqld
第一次启动mysql,会在日志文件中生成root用户的一个随机密码,使用下面命令查看该密码
grep 'temporary password' /var/log/mysqld.log
使用刚刚的临时密码登录后,修改密码
# mysql -u root -p -h localhost
Enter password:
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '1lin24QWE!@#';
mysql+pymysql://user:pwd@url:port/db_name
SHOW DATABASES;
USE db_name;
CREATE DATABASE `db_name` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
DROP DATABASE db_name;
SHOW TABLES;
DESC table_name;
exit
use mysql;
select user,host,password from user;
// 查看 user_name 在 host 下的权限
// host_address取值 ip/localhost/%
show grants for user_name@host_address;
show grants for user_name; //没有指定host则表示%
create user user_name@host_address identified by 'password'; // 不指定host为%
例子:
create user lxp@localhost identified by 'lxps_password';
create user lxp@106.15.188.215 identified by 'lxps_password';
set password for user_name@'host_address'=password('pwd');
flush privileges;
-- -----------------或者------------------
update user set password=password('iamsuperman') where user='superboy';
flush privileges;
delete from user where user=‘user_name‘ and host=‘host_address‘
DROP USER username@localhost;
grant all on db_name.* to user_name@host_address identified by 'pwd';
flush privileges; // 一定要刷新权限
-- 赋予部分权限,其中的shopping.*表示对以shopping所有文件操作。
grant select,delete,update,insert on simpleshop.* to superboy@'localhost' identified by 'superboy';
flush privileges;
-- 赋予所有权限
grant all privileges on simpleshop.* to superboy@localhost identified by 'iamsuperboy';
flush privileges;
-- 撤销update权限
revoke update on simpleshop.* from superboy@localhost;
-- 撤销所有权限
revoke all on simpleshop.* from superboy@localhost;
原文:https://www.cnblogs.com/1lin24/p/11726299.html