Alibaba Cloud Centos7.3 Installation mysql5.7. 18 rpm Installation Tutorial

  • 2021-08-17 01:16:33
  • OfStack

Uninstall MariaDB

CentOS 7 installs MariaDB instead of MySQL by default, and MySQL-related packages have been removed from the yum server. Because MariaDB and MySQL may conflict, uninstall MariaDB first.

1. Before installing the new version of mysql, we need to uninstall the mariadb-lib that comes with the system

[root@iZwz94qazh62gk5ewl4ei2Z home]# rpm -qa | grep -i mariadb
mariadb-libs-5.5.52-1.el7.x86_64
[root@iZwz94qazh62gk5ewl4ei2Z home]# rpm -e --nodeps mariadb-libs-5.5.52-1.el7.x86_64

2. Download the rpm collection package of the latest version of mysql from the official website of mysql: mysql-5. 7.18-1.el6.x86_64.rpm-bundle. tar

3. Upload mysql-5. 7.18-1.el6.x86_64. rpm-bundle. tar to the linux server and extract the tar packet


[root@iZwz94qazh62gk5ewl4ei2Z home]# mkdir mysql
[root@iZwz94qazh62gk5ewl4ei2Z home]# tar -xf mysql-5.7.18-1.el6.x86_64.rpm-bundle.tar -C mysql
[root@iZwz94qazh62gk5ewl4ei2Z home]# cd mysql
[root@iZwz94qazh62gk5ewl4ei2Z mysql]# ll
total 459492
-rw-r--r-- 1 7155 31415 23618836 Mar 20 17:40 mysql-community-client-5.7.18-1.el6.x86_64.rpm
-rw-r--r-- 1 7155 31415  335496 Mar 20 17:40 mysql-community-common-5.7.18-1.el6.x86_64.rpm
-rw-r--r-- 1 7155 31415  3747352 Mar 20 17:40 mysql-community-devel-5.7.18-1.el6.x86_64.rpm
-rw-r--r-- 1 7155 31415 39086508 Mar 20 17:40 mysql-community-embedded-5.7.18-1.el6.x86_64.rpm
-rw-r--r-- 1 7155 31415 135869292 Mar 20 17:40 mysql-community-embedded-devel-5.7.18-1.el6.x86_64.rpm
-rw-r--r-- 1 7155 31415  2177064 Mar 20 17:40 mysql-community-libs-5.7.18-1.el6.x86_64.rpm
-rw-r--r-- 1 7155 31415  1723180 Mar 20 17:40 mysql-community-libs-compat-5.7.18-1.el6.x86_64.rpm
-rw-r--r-- 1 7155 31415 159060212 Mar 20 17:41 mysql-community-server-5.7.18-1.el6.x86_64.rpm
-rw-r--r-- 1 7155 31415 104881084 Mar 20 17:41 mysql-community-test-5.7.18-1.el6.x86_64.rpm

4. Install using the rpm-ivh command


[root@iZwz94qazh62gk5ewl4ei2Z mysql]# rpm -ivh mysql-community-common-5.7.18-1.el6.x86_64.rpm
warning: mysql-community-common-5.7.18-1.el6.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing...             ################################# [100%]
Updating / installing...
  1:mysql-community-common-5.7.18-1.e################################# [100%]
[root@iZwz94qazh62gk5ewl4ei2Z mysql]# rpm -ivh mysql-community-libs-5.7.18-1.el6.x86_64.rpm
warning: mysql-community-libs-5.7.18-1.el6.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing...             ################################# [100%]
Updating / installing...
  1:mysql-community-libs-5.7.18-1.el6################################# [100%]
[root@iZwz94qazh62gk5ewl4ei2Z mysql]# rpm -ivh mysql-community-client-5.7.18-1.el6.x86_64.rpm
warning: mysql-community-client-5.7.18-1.el6.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing...             ################################# [100%]
Updating / installing...
  1:mysql-community-client-5.7.18-1.e################################# [100%]
[root@iZwz94qazh62gk5ewl4ei2Z mysql]# rpm -ivh mysql-community-server-5.7.18-1.el6.x86_64.rpm
warning: mysql-community-server-5.7.18-1.el6.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing...             ################################# [100%]
Updating / installing...
  1:mysql-community-server-5.7.18-1.e################################# [100%]
[root@iZwz94qazh62gk5ewl4ei2Z mysql]# 

The above several packages have dependencies and are executed successively.

Install mysql using the rpm installation method, and the installation path is as follows:


a  Database directory 
/var/lib/mysql/
b  Configuration file 
/usr/share/mysql(mysql.server Commands and configuration files )
c  Related commands 
/usr/bin(mysqladmin mysqldump Wait for an order )
d  Startup script 
/etc/rc.d/init.d/( Startup script file mysql Directory of )
e /etc/my.conf

5. Database initialization

In order to ensure that the database directory is mysql login user and the owner of the file is mysql login user, if your linux system runs mysql service as root, you need to execute the following command to initialize


[root@iZwz94qazh62gk5ewl4ei2Z mysql]# mysqld --initialize --user=mysql

If you are running as an mysql login, you can remove the--user option.

In addition-the initialize option is initialized in "secure" mode by default, which will generate a password for root users and mark the password as expired. After logging in, you need to set a new password.

And use --initialize-insecure Command does not use safe mode, and 1 password will not be generated for root users.

This demonstration uses-initialize initialization, will generate 1 root account password, password in log file, red area is automatically generated password


[root@iZwz94qazh62gk5ewl4ei2Z mysql]# cat /var/log/mysqld.log
2017-06-05T14:30:52.709474Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2017-06-05T14:30:55.590590Z 0 [Warning] InnoDB: New log files created, LSN=45790
2017-06-05T14:30:56.000269Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2017-06-05T14:30:56.109868Z 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: 960c533e-49fb-11e7-91f2-00163e089fd2.
2017-06-05T14:30:56.116186Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2017-06-05T14:30:56.116777Z 1 [Note] A temporary password is generated for root@localhost: :Wu?2QQutQwj

Start the mysql database now systemctl start mysqld.service (Centos7 unique startup mode)


[root@iZwz94qazh62gk5ewl4ei2Z mysql]# systemctl start mysqld.service

mysql can be stopped, started, and restarted using the following two commands:

Start:

Start with service: service mysqld start
Start with the mysqld script:/etc/inint. d/mysqld start
Start with safe_mysqld: safe_mysqld &

Stop:

Start with service: service mysqld stop
Start with the mysqld script:/etc/inint. d/mysqld stop
mysqladmin shutdown

Restart:

Start with service: service mysqld restart
Start with the mysqld script:/etc/inint. d/mysqld restart

Connect to a database

[root@iZwz94qazh62gk5ewl4ei2Z mysql]# mysql -u root -p
Enter password:

Password input:: Wu? 2QQutQwj

Change password:

set password = password ('Your Password');
Setting up remote access


grant all privileges on *.* to 'root' @'%' identified by '123456'; 
flush privileges;

Set mysql boot

Join the system service:


chkconfig --add mysql

Auto start:


chkconfig mysql on

Query list:


chkconfig

Note: None of them are turned off (off), but there is no automatic start.


Related articles: