Centos install mysql and how to use it

0. Environment

Operating system for this article: CentOS 7.2.1511 x86_64
MySQL version: 5.7.16

1. Uninstall the mariadb-lib that comes with the system

[root@centos-linux ~]# rpm -qa|grep mariadb
 mariadb-libs-5.5.44-2.el7.centos.x86_64
[root@centos-linux ~]# rpm -e mariadb-libs-5.5.44-2.el7.centos.x86_64 --nodeps

2. Download the mysql5.7.16 rpm installation package, the latest mysql installation package on the official website is mysql-5.7.16-1.el7.x86_64.rpm-bundle.tar download address

[root@centos-linux ~]# wget http://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.16-1.el7.x86_64.rpm-bundle.tar

then unzip


 [root@linux_node_1 src]# tar -xvf mysql-5.7.16-1.el7.x86_64.rpm-bundle.tar
  mysql-community-libs-compat-5.7.16-1.el7.x86_64.rpm
  mysql-community-devel-5.7.16-1.el7.x86_64.rpm
  mysql-community-minimal-debuginfo-5.7.16-1.el7.x86_64.rpm
  mysql-community-libs-5.7.16-1.el7.x86_64.rpm
  mysql-community-common-5.7.16-1.el7.x86_64.rpm
  mysql-community-embedded-compat-5.7.16-1.el7.x86_64.rpm
  mysql-community-test-5.7.16-1.el7.x86_64.rpm
  mysql-community-embedded-devel-5.7.16-1.el7.x86_64.rpm
  mysql-community-server-minimal-5.7.16-1.el7.x86_64.rpm
  mysql-community-server-5.7.16-1.el7.x86_64.rpm
  mysql-community-client-5.7.16-1.el7.x86_64.rpm
  mysql-community-embedded-5.7.16-1.el7.x86_64.rpm
3. Installation
Execute in sequence (several packages have dependencies, so they are executed sequentially) The following commands are installed
[root@centos-linux ~]# rpm -ivh mysql-community-common-5.7.16-1.el7.x86_64.rpm
[root@centos-linux ~]# rpm -ivh mysql-community-libs-5.7.16-1.el7.x86_64.rpm
[root@centos -linux ~]# rpm -ivh mysql-community-client-5.7.16-1.el7.x86_64.rpm
[root@centos-linux ~]# rpm -ivh mysql-community-server-5.7.16-1.el7 .x86_64.rpm
reported the following error when installing rpm -ivh mysql-community-server-5.7.16-1.el7.x86_64.rpm:

  [root@linux_node_1 src]# rpm -ivh mysql-community-server-5.7.16-1.el7.x86_64.rpm
  warning: mysql-community-server-5.7.16-1.el7.x86_64.rpm: Header V3 DSA /SHA1 Signature, key ID 5072e1f5: NOKEY
  error: Failed dependencies:
  libaio.so.1()(64bit) is needed by mysql-community-server-5.7.16-1.el7.x86_64
  libaio.so.1(LIBAIO_0. 1)(64bit) is needed by mysql-community-server-5.7.16-1.el7.x86_64
  libaio.so.1(LIBAIO_0.4)(64bit) is needed by mysql-community-server-5.7.16-1 .el7.x86_64
  net-tools is needed by mysql-community-server-5.7.16-1.el7.x86_64
  This error means that you need to install the libaio package and the net-tools package: you can install it with yum and install libaio-0.3. 107-10.el6.x86_64.rpm, download address:
wget http://mirror.centos.org/centos/6/os/x86_64/Packages/libaio-0.3.107-10.el6.x86_64.rpm
Then yum install net-tools yum install net-tools After completion, you can install it smoothly
4. Database initialization

In order to ensure that the database directory and the owner of the file are the mysql login user, if you are running the mysql service as root, you need to execute the following command to initialize
mysqld --initialize --user=mysql

If the command execution fails, you can delete the mysql data directory to solve the problem. rm /var/lib/mysql
  If you are running as mysql, you can remove the --user option.

  In addition, the --initialize option is initialized in "secure" mode by default, which will generate a password for the root user and mark the password as expired. After logging in, you need to set a new password, while using the --initialize-insecure command does not With safe mode, a password is not generated for the root user.

  The --initialize used in this demonstration will generate a root account password. The password is in the log file. The red area is the automatically generated password
  [root@linux_node_1 src]# cat /var/log/mysqld.log
  2016-12 -07T04:41:58.028558Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
  2016-12-07T04:41:58.315188Z 0 [Warning] InnoDB: New log files created, LSN=45790
  2016-12-07T04:41:58.355114Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
  2016-12-07T04:41:58.418448Z 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: 7cc98831-bc37-11e6-a263-000c29f902dc.
  2016-12-07T04:41:58.419935Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
  2016-12-07T04:41:58.420558Z 1 [Note] A temporary password is generated for root@localhost: )1r3gi,hjgQa
  现在启动mysql数据库systemctl start mysqld.service
  [root@linux_node_1 src]# systemctl start mysqld.service
  [root@linux_node_1 src]# mysql -u root -p
  Enter password:
  Welcome to the MySQL monitor.  Commands end with ; or \g.
  Your MySQL connection id is 2
  Server version: 5.7.16
  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>
 
  5. Change the password
 
  The password is marked as expired , if you want to use it normally, you need to modify the password
 
mysql> show databases;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.

 
  The previous password() function will be abandoned, the official recommendation is to use the following command to modify the password
 
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'new_password';

 
  At the same time, if the password you set is too simple, an error will be reported.
 
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '123';
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements

Set the account to allow remote access:

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

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324979396&siteId=291194637