Note (It is recommended to turn off the firewall and turn off selinux before installing mysql)
systemctl stop firewall.service #Stop firewall
systemctl disable firewall.service #Disable firewall from booting
firewall-cmd-state #Check the default firewall state (not running is displayed after shutdown)
And change the following line in the configuration file/etc/sysconfig/selinux to SELINUX=disabled
Step 1: Download mysql
mysql-5.7.21-linux-glibc2.12-x86_64.tar.gz The version I downloaded is 5.7.21
1: Check whether mysql is installed locally
rpm -qa | grep mysql
2: Uninstall previous mysql
rpm -e 已经存在的MySQL全名
Step 2: Extract the file
tar -zxvf mysql-5.7.21-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
Change the file name to mysql:
mv mysql-5.7.21-linux-glibc2.12-x86_64/ mysql
Step 3: Configure the startup file
vi /etc/my.cnf
[mysql]
default-character-set=utf8
[mysqld]
default-storage-engine=INNODB
character_set_server=utf8
Copy mysql.server to the/etc/init.d/directory (to achieve automatic execution effect on booting)
cp mysql.server /etc/init.d/mysql
Modify the/etc/init.d/mysql parameter
vi /etc/init.d/mysql
Modify the following content:
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
For security convenience, create a dedicated user to operate the database
Create a mysql group:
groupadd mysql
Create mysql users and put the users in the mysql group:
useradd -r -g mysql mysql
Set a password for mysql users:
passwd mysql
Change the owner of the directory/usr/local/mysql:
chown -R mysql:mysql /usr/local/mysql/
Step 4: Initialize mysql database
cd /usr/local/mysql/bin/
./ mysqld –initialize –user=mysql –basedir=/usr/local/mysql –datadir=/usr/local/mysql/data
After initialization, a temporary password will be generated, root@localhost: : *(It is best to record this temporary password first)
2. Encrypt the database
./ mysql_ssl_rsa_setup –datadir=/usr/local/mysql/data
3. start the MySQL
./ mysqld_safe –user=mysql
Step 5 Login:
./ mysql -uroot -p
Enter password: Enter the previous temporary password here
change the password
set password=password ('new password');
Remote connection opens:
GRANT ALL PRIVILEGES ON *.* TO ‘root’@’%’ IDENTIFIED BY ‘MyPassword’ WITH GRANT OPTION;
Step 6: Add mysql to the service and start it automatically
Configure environment variables
vi /etc/profile
Add the following two values at the bottom
export MYSQL_HOME=”/mysql”
export PATH=”$PATH:$MYSQL_HOME/bin”
then save
Make the modified profile file take effect immediately
source /etc/profile
Add mysql to the folder of the service that can be controlled to start, and name mysql, which is the name of the service that can be controlled by the service mysql start control
/etc/init.d is a link to/etc/rc.d/init.d. Adding a file in/etc/init.d will simultaneously add the same file under/etc/rc.d/init.d
cd /mysql/
cp support-files/mysql.server /etc/init.d/mysql
The chkconfig command is mainly used to update (start or stop) and query run-level information of system services. Keep in mind that chkconfig does not automatically disable or activate a service immediately, it simply changes the symbolic connection
- add : Adds the specified system service so that the chkconfig command can manage it, and adds relevant data to the system boot narrative file. Service scripts must be stored in the/etc/ini.d/directory
Add the mysql service to the list of services managed by boot instructions
chkconfig –add mysql
Boot on and start mysql service
on : The service targeted has a level limit. Query chkconfig for details
chkconfig mysql on
You can now start mysql using the following command
service mysql start
Stop mysql services
service mysql stop
Restart mysql service
service mysql restart