Software | Version |
---|---|
CentOS | CentOS 6 & CentOS 7 |
MySQL | 8.0.x |
Software | Version |
---|---|
CentOS | 7.4 Release |
MySQL | 8.0.11 |
# CentOS 7
cd /home/downloads
wget https://dev.mysql.com/get/mysql80-community-release-el7-1.noarch.rpm
sudo rpm -ivh mysql80-community-release-el7-1.noarch.rpm
# CentOS 6
cd /home/downloads
wget https://dev.mysql.com/get/mysql80-community-release-el6-1.noarch.rpm
sudo rpm -ivh mysql80-community-release-el6-1.noarch.rpm
# installation
sudo yum -y install mysql-community-server
# Start service
sudo systemctl start mysqld
# View version information
mysql -V
#1、 View the temporary password generated by MySQL for the Root account
grep "A temporary password"/var/log/mysqld.log
#2、 Enter MySQL shell
mysql -u root -p
#3、 change Password
ALTER USER 'root'@'localhost' IDENTIFIED BY 'Mypwd123!';
# CentOS 7
# Open port
firewall-cmd --add-port=3306/tcp --permanent
# Reload firewall settings
firewall-cmd --reload
# CentOS 6
iptables -I INPUT -p tcp --dport 3306-j ACCEPT
iptables save
Enter the security setup wizard
mysql_secure_installation
Security settings are roughly divided into the following steps
The following are examples of security settings;
Securing the MySQL server deployment.
Enter password for user root:
The existing password for the user account root has expired. Please set a newpassword.
New password:
Re-enter newpassword:
VALIDATE PASSWORD PLUGIN can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD plugin?
Press y|Y for Yes, any other key for No: N
Using existing password for root.
Change the password for root ?((Press y|Y for Yes, any other key for No): Y
New password:
Re-enter newpassword:
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment.
Remove anonymous users?(Press y|Y for Yes, any other key for No):... skipping.
Normally, root should only be allowed to connect from'localhost'. This ensures that someone cannot guess at
the root password from the network.
Disallow root login remotely?(Press y|Y for Yes, any other key for No): N
... skipping.
By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment.
Remove test database and access to it?(Press y|Y for Yes, any other key for No): N
... skipping.
Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.
Reload privilege tables now?(Press y|Y for Yes, any other key for No): Y
Success.
All done!
# New local user
CREATE USER 'test'@'localhost' IDENTIFIED BY 'Test@123456';
# New remote user
CREATE USER 'test'@'%' IDENTIFIED BY 'Test@123456';
# New database
CREATE DATABASE testdb;
# Grant the specified account the remote access authority to the specified database
GRANT ALL PRIVILEGES ON testdb.* TO 'test'@'%';
# Grant the specified account remote access permissions to all databases
GRANT ALL PRIVILEGES ON *.* TO 'test'@'%';
# Give the specified account local access to all databases
GRANT ALL PRIVILEGES ON *.* TO 'test'@'localhost';
# Refresh permissions
FLUSH PRIVILEGES;
#1、 View permissions
SHOW GRANTS FOR 'test'@'%';
#2、 Grant permissions
GRANT ALL PRIVILEGES ON *.* TO 'test'@'%';
#3、 Withdraw permission
REVOKE ALL PRIVILEGES ON *.* FROM 'test'@'%';
#4、 Refresh permissions
FLUSH PRIVILEGES;
#5、 delete users
DROP USER 'test'@'localhost';
[ root@centos7 download]# whereis my.cnf
my:/etc/my.cnf
# Modify the configuration file
vi /etc/my.cnf
# Modification 1: Add client configuration (beginning of file)
[ client]default-character-set=utf8mb4
# Modification 2: Add mysqld configuration (end of file)
# charset
character-set-server=utf8mb4
collation-server=utf8mb4_general_ci
# The configuration will take effect after restart
systemctl restart mysqld
Recommended Posts