此文章同步刊登於我的部落格
mkdir mysql
tar xvf mysql-5.7.35-1.el7.x86_64.rpm-bundle.tar -C ./mysql
cd mysql
ls -alh
rpm -ivh mysql-community-client* --nodeps --force
rpm -ivh mysql-community-common* --nodeps --force
rpm -ivh mysql-community-libs* --nodeps --force
rpm -ivh mysql-community-server* --nodeps --force
rpm -qa | grep mysql
systemctl start mysqld
systemctl status mysqld
預設的root密碼會在/var/log/mysqld.log裡
grep "A temporary password" /var/log/mysqld.log
# mysql_secure_installation
New password: NEW_PASSWORD
Re-enter new password: NEW_PASSWORD
Change the password for root ? N
Do you wish to continue with the password provided? Y
Remove anonymous users? (Press y|Y for Yes, any other key for No) : Y
Disallow root login remotely? (Press y|Y for Yes, any other key for No) : Y
Remove test database and access to it? (Press y|Y for Yes, any other key for No) : Y
Reload privilege tables now? (Press y|Y for Yes, any other key for No) : Y
ALTER USER 'root'@'localhost' IDENTIFIED BY 'NEW_PASSWORD';
FLUSH PRIVILEGES;
systemctl status firewalld
firewall-cmd --get-services | grep mysql
firewall-cmd --zone=public --permanent --add-service=mysql
firewall-cmd --zone=public --permanent --add-port=3306/tcp
firewall-cmd --zone=public --permanent --list-services
mysql -uroot -p --default-character-set=utf8 <SQL_FILE
CREATE USER 'user'@'CLIENT_IP' IDENTIFIED BY 'NEW_PASSWORD';
FLUSH PRIVILEGES;
ALTER USER 'root'@'localhost' PASSWORD EXPIRE NEVER;
FLUSH PRIVILEGES;
GRANT ALL PRIVILEGES ON `DB_NAME`.* TO 'user'@'CLIENT_IP' IDENTIFIED BY 'NEW_PASSWORD';
FLUSH PRIVILEGES;
SELECT user, host FROM mysql.user;
SHOW GRANTS FOR 'user'@'CLIENT_IP';
revoke all privileges on *.* from 'user'@'CLIENT_IP';
GRANT SELECT,UPDATE,INSERT,DELETE ON `DB_NAME`.* TO 'usernamep'@'localhost' IDENTIFIED BY PASSWORD 'password';
FLUSH PRIVILEGES;
DELETE FROM mysql.user WHERE user='USERNAME' AND host='HOST';
FLUSH PRIVILEGES;