Software | Version |
---|---|
CentOS | 8.2 Release |
MySQL | 8.0.21 |
Software | Version |
---|---|
CentOS | CentOS 8 |
MySQL | 8.0.21+ |
# CentOS 7
cd /home/downloads
wget https://dev.mysql.com/get/mysql80-community-release-el8-1.noarch.rpm
sudo rpm -ivh mysql80-community-release-el8-1.noarch.rpm
# installation
sudo yum install -y mysql-server
# Start service
sudo systemctl start mysqld
# View version information
mysql -V
# mysql Ver 8.0.21for Linux on x86_64(Source distribution)
#1、 Enter MySQL shell without password
mysql -u root
#2、 change Password
ALTER USER 'root'@'localhost' IDENTIFIED BY 'Mypwd123!';
# Open port
firewall-cmd --add-port=3306/tcp --permanent
# Reload firewall settings
firewall-cmd --reload
MySQL 8 adds a new security setting wizard, which simplifies the operation of security settings for deploying MySQL on the server, which is great.
Security settings are roughly divided into the following steps/options
The above steps/options can be done according to your needs.
mysql_secure_installation
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!
# Create database
mysql> CREATE DATABASE mydb;
# View all databases
mysql> SHOW DATABASES;
# Use data and create tables
mysql> USE mydb;
mysql> CREATE TABLE test(id int,body varchar(100));
# View table
mysql> SHOW TABLES;
# New local user
mysql> CREATE USER 'test'@'localhost' IDENTIFIED BY '123456';
# New remote user
mysql> CREATE USER 'test'@'%' IDENTIFIED BY '123456';
# Grant the specified account the remote access authority to the specified database
mysql> GRANT ALL PRIVILEGES ON mydb.* TO 'test'@'%';
# Grant the specified account remote access permissions to all databases
mysql> GRANT ALL PRIVILEGES ON *.* TO 'test'@'%';
# Give the specified account local access to all databases
mysql> GRANT ALL PRIVILEGES ON *.* TO 'test'@'localhost';
# Refresh permissions
mysql> 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
http://www.infoq.com/cn/articles/in-mysql-never-use-utf8-use-utf8
https://serverfault.com/questions/139323/how-to-bind-mysql-server-to-more-than-one-ip-address
Recommended Posts