sudo apt-get install mysql-server-5.7 service mysql start service mysql stop sudo apt-get remove mysql-server-5.7 # 数据存放目录 /var/lib/mysql # 配置存放目录 /etc/mysql
用户管理
1 2 3
# root用户登录 mysql -u root -p # 切勿修改root用户和使用root用户进行生产
# e.g.1 CREATE USER 'finley'@'localhost' IDENTIFIED BY 'password'; GRANT ALL PRIVILEGES ON *.* TO 'finley'@'localhost' WITH GRANT OPTION; GRANT ALL PRIVILEGES ON database.table TO 'finley'@'localhost' WITH GRANT OPTION; # e.g.2 CREATE USER 'finley'@'%' IDENTIFIED BY 'password'; GRANT ALL PRIVILEGES ON *.* TO 'finley'@'%' WITH GRANT OPTION; # e.g.3 CREATE USER 'admin'@'localhost' IDENTIFIED BY 'password'; GRANT RELOAD,PROCESS ON *.* TO 'admin'@'localhost'; # e.g.4 CREATE USER 'dummy'@'localhost';
# e.g.1 GRANT ALL ON db1.* TO 'jeffrey'@'localhost'; # e.g.2 GRANT SELECT ON db2.invoice TO 'jeffrey'@'localhost';
授权用户远程连接
1 2 3 4 5 6 7 8 9 10
# 检查一下3个配置文件是否有host绑定 /etc/mysql/mysql.cnf /etc/mysql/conf.d/mysql.cnf /etc/mysql/mysql.conf.d/mysql.cnf # 注释本地host绑定 bind-address = 127.0.0.1 # 授权用户可连接的host GRANT ALL PRIVILEGES ON *.* TO 'user'@'%' IDENTIFIED BY 'password' WITH GRANT OPTION; # 刷新授权 FLUSH PRIVILEGES;