First download MySQL and unzip it
Wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz tar XZVF Mysql - 5.7.24 - Linux - glibc2.12 - x86_64. Tar. GzCopy the code
Unzip it and rename it usr/local
Mv mysql-5.7.24-linux-glibc2.12-x86_64 /usr/local/cd /usr/local/mv mysql-5.7.24-linux-glibc2.12-x86_64 mysql-5.7.24-linux-glibc2.12-x86_64 mysqlCopy the code
Create a data directory in /usr/local/mysql
mkdir /usr/local/mysql/data
Copy the code
Check whether the mysql user group and user exist. If not, create the mysql user group
cat /etc/group | grep mysql
cat /etc/passwd |grep mysql
groupadd mysql
useradd -r -g mysql mysql
Copy the code
Change the user groups, users, and permissions of all directories and folders in the mysql directory
chown -R mysql:mysql /usr/local/mysql
chmod -R 755 /usr/local/mysql
Copy the code
cd /usr/local/mysql/bin
./mysqld --initialize --user=mysql --datadir=/usr/local/mysql/data --basedir=/usr/local/mysql
Copy the code
Edit the configuration file my.cnf and add the following configuration
vi /etc/my.cnf
[mysqld]
bind-address
datadir=/usr/local/mysql/data
port=3306
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
symbolic-links=0
max_connections=600
innodb_file_per_table=1
lower_case_table_names=1
character_set_server=utf8
Copy the code
Lower_case_table_names: indicates whether the table name is case sensitive. 1 indicates that the table name is lowercase when stored and case insensitive when operated. 0 indicates case-sensitive. The value cannot be set dynamically and must be restarted for the modification to take effect: CHARACTER_set_server: Sets the default character set for the database. If the default character set is not set, the default character set is latin1. Innodb_file_per_table: Specifies whether data of each table is stored separately. 0 indicates that the independent tablespace is disabled. You can view the differences in file structures by viewing data directories.
Test start mysql server
/usr/local/mysql/support-files/mysql.server start
Copy the code
If the following information is displayed, the database is successfully installed and started
Add a soft connection and restart the mysql service
ln -s /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
ln -s /usr/local/mysql/bin/mysql /usr/bin/mysql
service mysql restart
Copy the code
Log in to the mysql database and change the password (the password is the temporary password generated in Step 5).
Open Remote Connection
Open the corresponding port
1. Run the iptables -a INPUT -ptcp –dport port number -j ACCEPT command to open the port. 2
Don’t forget to turn on the firewall
Check whether port 3306 is developed on the firewall. Firewall-cmd --query-port=3306/ TCP Firewall-cmd --permanent --add-port=3306/ TCPCopy the code
Set automatic startup upon startup
1. Copy the service file to init.d. Mysql [root@localhost /]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld [root@localhost /]# chmod +x /etc/init.d/mysqld [root@localhost /]# chkconfig --listCopy the code
Next, try Navicat on your computer to connect to MySQL in the cloud server
Done!