Installing MySQL under CentOS 7
Step 1: Download MySQL
[root@tencent-centos1 opt]# wget http://mirrors.sohu.com/mysql/MySQL-5.7/mysql-5.7.17-linux-glibc2.5-x86_64.tar.gz
Step 2: Unzip and download to MySQL package
1. Decompression package.
Command template
The directory where the tar-zxvf compression package is located - the directory that you want to place after C compression
For example, bloggers put compressed packages in the / opt/software directory and extract them into / opt.
[root@VM_161_76_centos opt]# tar -zxvf software/mysql-5.7.17-linux-glibc2.5-x86_64.tar.gz -C /opt/
2. You can create a soft link
[root@VM_161_76_centos opt]# ln -s mysql-5.7.17-linux-glibc2.5-x86_64/ /opt/mysql
3. Create a data directory under the decompressed directory
[root@VM_161_76_centos opt]# cd mysql
[root@VM_161_76_centos mysql]# mkdir data
Step 3: Configure related files
1. First configuration file
[root@VM_161_76_centos opt]# cp mysql/support-files/my-default.cnf /etc/my.cnf
Some support-files do not have my-default.cnf files. Then create one by yourself.
Add the following to the document
[mysql]
default-character-set=utf8
[mysqld]
basedir = /opt/mysql
datadir = /opt/mysql/data
port = 3306
default-storage-engine=INNODB
character_set_server=utf8
2. Second configuration file
[root@VM_161_76_centos opt]# cp mysql/support-files/mysql.server /etc/init.d/mysql
Configure the following in the etc/init.d/mysql file
basedir=/opt/mysql
datadir=/opt/mysql/data
3. Adding User Groups and User mysql
[root@VM_161_76_centos opt]# groupadd mysql
[root@VM_161_76_centos opt]# useradd -r -g mysql
The following can see if the creation was successful:
[root@VM_161_76_centos opt]# cat /etc/group | grep mysql
mysql:x:1002:
[root@VM_161_76_centos opt]# cat /etc/passwd | grep mysql
mysql:x:995:1002::/home/mysql:/bin/bash
A similar occurrence after entering the command indicates that the creation was successful.
After creation, change the group and user to which the decompressed package belongs
[root@VM_161_76_centos opt]# chown -R mysql:mysql mysql-5.7.17-linux-glibc2.5-x86_64/
4. Configuring environment variables
[root@VM_161_76_centos opt]# vim /etc/profile
Add the following to the open file to save
export MYSQL=/opt/mysql
export PATH=$MYSQL/bin:$PATH
Make the configuration effective and execute
[root@VM_161_76_centos opt]# source /etc/profile
Step 4: Initialize and start the service
1. Initialization of database
[root@VM_161_76_centos mysql]# ./bin/mysqld --initialize --user=mysql --basedir=/opt/mysql --datadir=/opt/mysql/data
2018-03-18T06:57:26.441070Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2018-03-18T06:57:26.441136Z 0 [Warning] 'NO_ZERO_DATE', 'NO_ZERO_IN_DATE' and 'ERROR_FOR_DIVISION_BY_ZERO' sql modes should be used with strict mode. They will be merged with strict mode in a future release.
2018-03-18T06:57:26.441141Z 0 [Warning] 'NO_AUTO_CREATE_USER' sql mode was not set.
2018-03-18T06:57:27.427075Z 0 [Warning] InnoDB: New log files created, LSN=45790
2018-03-18T06:57:27.633941Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2018-03-18T06:57:27.728128Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 9ebb3fa6-2a79-11e8-84cd-525400ccdcec.
2018-03-18T06:57:27.737320Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2018-03-18T06:57:27.752672Z 1 [Note] A temporary password is generated for root@localhost: 7j)Nu!EatnIb
The last temporary password must be saved, such as the 7j)Nu!EatnIb of the blogger.
2. Start MySQL
[root@VM_161_76_centos mysql]# ./bin/mysqld_safe --user=mysql &
Enter bg and run in background mode. Check to see if there is a corresponding process
[root@VM_161_76_centos opt]# ps -ef|grep mysql
root 30379 24544 0 15:16 pts/0 00:00:00 /bin/sh ./bin/mysqld_safe
mysql 30525 30379 0 15:16 pts/0 00:00:00 ./bin/mysqld --basedir=/opt/mysql --datadir=/opt/mysql/data --plugin-dir=/opt/mysql/lib/plugin --user=mysql --log-error=/opt/mysql/data/VM_161_76_centos.err --pid-file=/opt/mysql/data/VM_161_76_centos.pid --port=3306
root 32295 24544 0 15:54 pts/0 00:00:00 grep --color=auto mysql
Enter MySQL:
Enter the previous temporary password when entering the password
[root@VM_161_76_centos opt]# mysql -uroot -p
Enter password:
3. Modify password after successful entry
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 6
Server version: 5.7.17 MySQL Community Server (GPL)
Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> set password = password('123456');
4. Give remote access privileges
mysql> grant all privileges on *.* to root@'%' identified by 'Your password';
So far the installation is complete!
Remarks:
There may be some problems in the middle, below the small record.
1. For example, when entering MySQL for the first time, the following problems arise. There are many solutions on the Internet, MySQL defaults to go to / tmp to find mysql.sock file.
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock'
Solution:
If my.cnf file does not configure socket = a directory similar to its own, kill all processes related to mysql, enter the installation directory of MySQL, and re-execute the following commands
[root@VM_161_76_centos mysql]# ./bin/mysqld_safe&
Then enter MySQL. Or enter the previous temporary password.