MySQL对libaio库有依赖关系,如果没有这个包,数据目录初始化和接下来的服务启动会失败。
yum install libaio创建软件安装目录mkdir /mysql_software下载软件Percona官网的下载页面有两个二进制Tar包,分别对应不同的发行版本ssl100 - Debian/Ubuntussl101 - for CentOS 6 and CentOS 7cd /mysql_softwarewget https://www.percona.com/downloads/Percona-Server-5.7/Percona-Server-5.7.17-11/binary/tarball/Percona-Server-5.7.17-11-Linux.x86_64.ssl101.tar.gz解压安装包[root@localhost mysql_software]# tar xvfz Percona-Server-5.7.17-11-Linux.x86_64.ssl101.tar.gz建立软链接[root@localhost mysql_software]# ln -s Percona-Server-5.7.17-11-Linux.x86_64.ssl101 data创建mysql用户[root@localhost ~]# groupadd mysql[root@localhost ~]# useradd -r -g mysql -s /bin/false mysql创建数据目录[root@localhost ~]# mkdir /mysql_data[root@localhost ~]# chmod 750 /mysql_data/[root@localhost ~]# chown -R mysql /mysql_data/[root@localhost ~]# chgrp -R mysql /mysql_data/[root@localhost /]# chown -R mysql /mysql_software/Percona-Server-5.7.17-11-Linux.x86_64.ssl101[root@localhost /]# chgrp -R mysql /mysql_software/Percona-Server-5.7.17-11-Linux.x86_64.ssl101
初始化MySQL数据库的数据文件路径,并且创建系统表[root@localhost ~]# cd /mysql_software/Percona-Server-5.7.17-11-Linux.x86_64.ssl101
[root@localhost Percona-Server-5.7.17-11-Linux.x86_64.ssl101]# bin/mysqld --initialize-insecure --user=mysql --basedir=/mysql_software/Percona-Server-5.7.17-11-Linux.x86_64.ssl101 --datadir=/mysql_data#./bin/mysqld --defaults-file=/opt/mysql_5.7.17/etc/my.cnf --initialize-insecure --user=mysql(配置文件初始化)
查看日志,若没有配置日志,则会将信息输出到屏幕[root@localhost Percona-Server-5.7.17-11-Linux.x86_64.ssl101]# cat log/mysqld_0.log 2017-02-12T16:11:08.723816Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2017-02-12T16:11:11.544515Z 0 [Warning] InnoDB: New log files created, LSN=457902017-02-12T16:11:12.004732Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.2017-02-12T16:11:12.075390Z 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: df2a104a-f13d-11e6-8cdd-000c292a9abe.2017-02-12T16:11:12.076947Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.2017-02-12T16:11:12.446251Z 0 [Warning] CA certificate ca.pem is self signed.2017-02-12T16:11:12.756727Z 1 [Warning] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.[root@localhost Percona-Server-5.7.17-11-Linux.x86_64.ssl101]# bin/mysql_ssl_rsa_setup如果配置文件中没有指定数据文件的路径,默认路径是/var/lib/mysql如果在配置文件/etc/my.cnf中指定了数据文件的路径,则会根据这个路径进行生成mkdir -p /mysql_software/Percona-Server-5.7.17-11-Linux.x86_64.ssl101/log[root@localhost ~]# cat /etc/my.cnf [mysqld]basedir = /mysql_software/Percona-Server-5.7.17-11-Linux.x86_64.ssl101datadir=/mysql_datasocket=/mysql_software/Percona-Server-5.7.17-11-Linux.x86_64.ssl101/log/mysql.sockuser=mysql# Disabling symbolic-links is recommended to prevent assorted security riskssymbolic-links=0log-error=/mysql_software/Percona-Server-5.7.17-11-Linux.x86_64.ssl101/log/mysqld_0.log[mysqld_safe]pid-file=/mysql_software/Percona-Server-5.7.17-11-Linux.x86_64.ssl101/log/mysqld.pid更改软件目录和数据目录权限[root@localhost Percona-Server-5.7.17-11-Linux.x86_64.ssl101]# chown -R root /mysql_software/Percona-Server-5.7.17-11-Linux.x86_64.ssl101[root@localhost Percona-Server-5.7.17-11-Linux.x86_64.ssl101]# chown -R mysql /mysql_data/
启动数据库[root@localhost Percona-Server-5.7.17-11-Linux.x86_64.ssl101]# bin/mysql --socket=/mysql_software/Percona-Server-5.7.17-11-Linux.x86_64.ssl101/log/mysql.sockWelcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 3Server version: 5.7.17-11 Percona Server (GPL), Release 11, Revision f60191cCopyright (c) 2009-2016 Percona LLC and/or its affiliatesCopyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql> show databases;+--------------------+| Database |+--------------------+| information_schema || mysql || performance_schema || sys |+--------------------+4 rows in set (0.00 sec)mysql> select user, host from mysql.user;+-----------+-----------+| user | host |+-----------+-----------+| mysql.sys | localhost || root | localhost |+-----------+-----------+2 rows in set (0.00 sec)更改root密码mysql> set password = password('root');Query OK, 0 rows affected, 1 warning (0.00 sec)mysql> show warnings;+---------+------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------+| Level | Code | Message |+---------+------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------+| Warning | 1287 | 'SET PASSWORD = PASSWORD('')' is deprecated and will be removed in a future release. Please use SET PASSWORD = '' instead |+---------+------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------+1 row in set (0.00 sec)mysql> flush privileges;Query OK, 0 rows affected (0.00 sec)[root@localhost Percona-Server-5.7.17-11-Linux.x86_64.ssl101]# bin/mysql -uroot -p --socket=/mysql_software/Percona-Server-5.7.17-11-Linux.x86_64.ssl101/log/mysql.sockEnter password: Welcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 6Server version: 5.7.17-11 Percona Server (GPL), Release 11, Revision f60191cCopyright (c) 2009-2016 Percona LLC and/or its affiliatesCopyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql> 关闭数据库[root@localhost Percona-Server-5.7.17-11-Linux.x86_64.ssl101]# ./bin/mysqladmin -uroot shutdown -p --socket=/mysql_software/Percona-Server-5.7.17-11-Linux.x86_64.ssl101/log/mysql.sockEnter password: 2017-02-12T16:32:21.505954Z mysqld_safe mysqld from pid file /mysql_software/Percona-Server-5.7.17-11-Linux.x86_64.ssl101/log/mysqld.pid ended[1]+ Done ./bin/mysqld_safe --defaults-file=/etc/my.cnf[root@localhost Percona-Server-5.7.17-11-Linux.x86_64.ssl101]# ps -ef|grep mysqlroot 4132 2523 0 08:32 pts/0 00:00:00 grep mysql[root@localhost Percona-Server-5.7.17-11-Linux.x86_64.ssl101]# ./bin/mysqld_safe --defaults-file=/etc/my.cnf &[1] 4134[root@localhost Percona-Server-5.7.17-11-Linux.x86_64.ssl101]# mysqld_safe Adding '/mysql_software/Percona-Server-5.7.17-11-Linux.x86_64.ssl101/lib/mysql/libjemalloc.so.1' to LD_PRELOAD for mysqld2017-02-12T16:32:41.691299Z mysqld_safe Logging to '/mysql_software/Percona-Server-5.7.17-11-Linux.x86_64.ssl101/log/mysqld_0.log'.2017-02-12T16:32:41.701689Z mysqld_safe Logging to '/mysql_software/Percona-Server-5.7.17-11-Linux.x86_64.ssl101/log/mysqld_0.log'.2017-02-12T16:32:41.742249Z mysqld_safe Starting mysqld daemon with databases from /mysql_data本文出自http://blog.itpub.net/26506993/viewspace-2133434/