下载
wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz
创建用户和组及变更权限
groupadd mysql
useradd mysql -g mysql
passwd mysql
mkdir -p /u01
mkdir -p /data/mysql
mkdir -p /data/log
chown -R mysql:mysql /u01
chmod -R 775 /u01
chown -R mysql:mysql /data
chmod -R 775 /data
[mysql@redis02 u01]$ ln -s mysql-5.7.22-linux-glibc2.12-x86_64 mysql
关闭防火墙以及setenforce
1 service iptables stop 2 service iptables status 3 4 setenforce 0 5 getinforce
生成基本my.cnf
1 [root@redis02 support-files]# cat /etc/my.cnf 2 [mysqld] 3 #GENERAL 4 datadir=/data/mysql 5 socket=/data/mysql/mysql.sock 6 pid-file=/data/mysqld.pid 7 user=mysql 8 port=3306 9 default_storage_engine=InnoDB 10 #INNODB 11 innodb_buffer_pool_size = 128M 12 innodb_log_file_size=10M 13 innodb_file_per_table=1 14 innodb_flush_method=O_DIRECT 15 #MYISAM 16 key_buffer_size=10M 17 #LOGGING 18 log-error=/data/log/mysql-error.log 19 slow_query_log=1 #是否启用慢查询日志,1为启用,0为禁用 20 slow_query_log_file=/data/log/mysql-slow.log #指定慢查询日志文件的路径和名字,可使用绝对路径指定;默认值是'主机名_slow.log',位于datad 21 #OTHER 22 tmp_table_size=32M 23 max_heap_table_size=32M 24 #query_cache_type=0 25 #query_cache_size=0 26 max_connections=1000 27 thread_cache_size=100 28 #table_cache=100 29 open_files_limit=65535 30 [client] 31 socket=/data/mysql/mysql.sock 32 port=3306 33 user=root 34 password=ocm123
初始化
10 [mysql@redis02 mysql]$ bin/mysqld --no-defaults --initialize --basedir=/u01/mysql --datadir=/data/mysql 11 2019-05-27T08:32:11.102279Z 0 [Warning] Changed limits: max_open_files: 1024 (requested 5000) 12 2019-05-27T08:32:11.102403Z 0 [Warning] Changed limits: table_open_cache: 431 (requested 2000) 13 2019-05-27T08:32:11.102540Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details). 14 2019-05-27T08:32:11.691286Z 0 [Warning] InnoDB: New log files created, LSN=45790 15 2019-05-27T08:32:11.786458Z 0 [Warning] InnoDB: Creating foreign key constraint system tables. 16 2019-05-27T08:32:11.898076Z 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: ec740042-8059-11e9-8229-08002771e31b. 17 2019-05-27T08:32:11.995089Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened. 18 2019-05-27T08:32:11.995972Z 1 [Note] A temporary password is generated for root@localhost: Y-0GncpD7RL,
生成rsa
1 [mysql@redis02 mysql]$ bin/mysql_ssl_rsa_setup 2 Generating a 2048 bit RSA private key 3 ...+++ 4 ......................................................................+++ 5 writing new private key to 'ca-key.pem' 6 ----- 7 Generating a 2048 bit RSA private key 8 .........................................................................+++ 9 ......+++ 10 writing new private key to 'server-key.pem' 11 ----- 12 Generating a 2048 bit RSA private key 13 .......................................................................+++ 14 .................................+++ 15 writing new private key to 'client-key.pem' 16 -----
运行mysql
1 [mysql@redis02 mysql]$ bin/mysqld_safe --user=mysql & 2 [1] 20623 3 [mysql@redis02 mysql]$ 2019-05-27T08:34:36.361814Z mysqld_safe Logging to '/data/log/mysql-error.log'. 4 2019-05-27T08:34:36.388677Z mysqld_safe Starting mysqld daemon with databases from /data/mysql
使用临时密码登录修改root密码
1 [mysql@redis02 log]$ mysql -u root -p 2 Enter password: 3 Welcome to the MySQL monitor. Commands end with ; or g. 4 Your MySQL connection id is 2 5 Server version: 5.7.22-log 6 7 Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved. 8 9 Oracle is a registered trademark of Oracle Corporation and/or its 10 affiliates. Other names may be trademarks of their respective 11 owners. 12 13 Type 'help;' or 'h' for help. Type 'c' to clear the current input statement. 14 15 mysql> alter user 'root'@'localhost' identified by 'ocm123'; 16 Query OK, 0 rows affected (0.00 sec) 17 18 mysql> exit 19 Bye
查看临时密码
grep 'temporary password' /data/log/mysql-error.log
脚本拷贝
1 [root@redis02 support-files]# ls 2 magic mysqld_multi.server mysql-log-rotate mysql.server 3 [root@redis02 support-files]# cp mysql.server /etc/init.d/mysqld
chmod mysql:mysql /etc/init.d/mysqld
重启mysql
/etc/init.d/mysqld restart
做测试时basedir 和 datadir概念没搞明白浪费很长时间