System environment
Centos-7
mysql version
mysql-5.7.17
1. Download and unzip rpm package
[root@VM_42_245_centos ~]# tar xf mysql-5.7.17-1.el7.x86_64.rpm-bundle.tar
[root@VM_42_245_centos ~]# ls
mysql-5.7.17-1.el7.x86_64.rpm-bundle.tar
mysql-community-client-5.7.17-1.el7.x86_64.rpm
mysql-community-common-5.7.17-1.el7.x86_64.rpm
mysql-community-devel-5.7.17-1.el7.x86_64.rpm
mysql-community-embedded-5.7.17-1.el7.x86_64.rpm
mysql-community-embedded-compat-5.7.17-1.el7.x86_64.rpm
mysql-community-embedded-devel-5.7.17-1.el7.x86_64.rpm
mysql-community-libs-5.7.17-1.el7.x86_64.rpm
mysql-community-libs-compat-5.7.17-1.el7.x86_64.rpm
mysql-community-minimal-debuginfo-5.7.17-1.el7.x86_64.rpm
mysql-community-server-5.7.17-1.el7.x86_64.rpm
mysql-community-server-minimal-5.7.17-1.el7.x86_64.rpm
mysql-community-test-5.7.17-1.el7.x86_64.rpm
2. Clear the original installation package and yum source
[root@VM_42_245_centos ~]# rpm -qa |grep mariadb
mariadb-libs-5.5.50-1.el7_2.x86_64
[root@VM_42_245_centos ~]# rpm -e --nodeps mariadb-libs-5.5.50-1.el7_2.x86_64
3. Add user
[root@VM_42_245_centos ~]# useradd -s /sbin/nologin mysql
4. Install mysql
[root@VM_42_245_centos ~]# rpm -ivh mysql-community-common-5.7.17-1.el7.x86_64.rpm
[root@VM_42_245_centos ~]# rpm -ivh mysql-community-libs-5.7.17-1.el7.x86_64.rpm
[root@VM_42_245_centos ~]# rpm -ivh mysql-community-devel-5.7.17-1.el7.x86_64.rpm
[root@VM_42_245_centos ~]# rpm -ivh mysql-community-client-5.7.17-1.el7.x86_64.rpm
[root@VM_42_245_centos ~]# rpm -ivh mysql-community-libs-compat-5.7.17-1.el7.x86_64.rpm
[root@VM_42_245_centos ~]# yum -y install numactl-libs
[root@VM_42_245_centos ~]# rpm -ivh mysql-community-server-5.7.17-1.el7.x86_64.rpm
The / etc/my.cnf file has been automatically generated in 5.7
5. Initialize mysql
[root@VM_42_245_centos lib]# cd /usr/bin/
[root@VM_42_245_centos bin]# mysqld --initialize --user=mysql
[root@VM_42_245_centos bin]# systemctl start mysqld
View the root password of mysql
[root@VM_42_245_centos bin]# cat /var/log/mysqld.log |grep pass
Security initialization
[root@VM_42_245_centos bin]# mysql_secure_installation
Enter the root password, and then enter the new password. The required length of the new password should be greater than 8 digits, and then enter "y" for all
6. Log in mysql database
[root@VM_42_245_centos bin]# mysql -uroot -p
mysql> select version();
+-----------+
| version() |
+-----------+
| 5.7.17 |
+-----------+
1 row in set (0.00 sec)
7. Add remote login user
By default, only the root account is allowed to log in locally. If you want to connect mysql on other machines, you must modify the root account to allow remote connection, or add an account to allow remote connection. For security reasons, I will add a new account:
mysql> GRANT ALL PRIVILEGES ON *.* TO 'username'@'%' IDENTIFIED BY 'password' WITH GRANT OPTION;
8. Configure the default encoding to UTF-8
Modify the / etc/my.cnf configuration file, and add the encoding configuration under [mysqld], as shown below:
[mysqld]
character_set_server=utf8
init_connect='SET NAMES utf8'
Restart mysql service and check the default database code as follows:
mysql installation completed!