1.下载:
mysql-5.7.25-linux-glibc2.12-x86_64.tar.gz并解压
2.安装 yum search libaioyum search libaio yum install libaio
3.增加用户何用户组
groupadd mysqluseradd -r -g mysql -s /bin/false mysql
4.mysql初始化
[root@localhost mysql]# bin/mysqld --initialize --user=mysql2019-03-27T03:50:57.227514Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).2019-03-27T03:50:57.433350Z 0 [Warning] InnoDB: New log files created, LSN=457902019-03-27T03:50:57.478308Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.2019-03-27T03:50:57.535988Z 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: 8759eef1-5043-11e9-8123-000c29b1e7cf.2019-03-27T03:50:57.537098Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.2019-03-27T03:50:57.538588Z 1 [Note] A temporary password is generated for root@localhost: G.vlOFW7m+8d
5.安装附加协议
bin/mysql_ssl_rsa_setupGenerating a 2048 bit RSA private key...............+++.......................................................................+++writing new private key to 'ca-key.pem'-----Generating a 2048 bit RSA private key...+++.................................................................+++writing new private key to 'server-key.pem'-----Generating a 2048 bit RSA private key....................+++...+++writing new private key to 'client-key.pem'-----
6.mysql启动
[root@localhost mysql]# bin/mysqld_safe --user=mysql&[1] 80177[root@localhost mysql]# Logging to '/usr/local/mysql/data/localhost.localdomain.err'.2019-03-27T03:54:09.318834Z mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql/data
7.拷贝启动命令文件到启动项目
cp -a support-files/mysql.server /etc/init.d/mysql.server
此时 ,可以通过如下代码操作
[root@localhost mysql]# service mysql.server statusUsage: mysql.server {start|stop|restart|reload|force-reload|status} [ MySQL server options ]
8.添加mysql命令全局可用
ln -s /usr/local/mysql/bin/mysql /usr/bin/
9.登入mysql,密码为步骤4最后显示的字符
mysql -u root -p
此时无法进行sql执行,需要重新更改默认root密码才能操作
10.关闭mysql,并以跳过验证模式启动
[root@localhost mysql]# service mysql.server stop Shutting down MySQL.. SUCCESS! [root@localhost mysql]# mysqld_safe --skip-grant-tables &[1] 96772[root@localhost mysql]# 2019-03-27T05:38:04.193707Z mysqld_safe Logging to '/usr/local/mysql/data/localhost.localdomain.err'.
此时登陆root账户 ,无需密码,同时修改密码个刷新配置。
[root@localhost mysql]# mysql -u root Welcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 2Server version: 5.7.25 MySQL Community Server (GPL)..........mysql> update user set authentication_string=password('1234'),password_expired='N' where user='root';Query OK, 1 row affected, 1 warning (0.00 sec)Rows matched: 1 Changed: 1 Warnings: 1mysql> flush privileges;Query OK, 0 rows affected (0.00 sec)
11.关闭当前mysql,以正常模式启动mysql,即可通过设定密码使用
[root@localhost mysql]# service mysql.server stopShutting down MySQL..2019-03-27T05:52:35.767193Z mysqld_safe mysqld from pid file /usr/local/mysql/data/localhost.localdomain.pid ended SUCCESS! [1]+ Done mysqld_safe --skip-grant-tables[root@localhost mysql]# mysqld_safe --user=mysql &[1] 117801[root@localhost mysql]# 2019-03-27T05:52:40.700667Z mysqld_safe Logging to '/usr/local/mysql/data/localhost.localdomain.err'.2019-03-27T05:52:40.745950Z mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql/data[root@localhost mysql]# mysql -u root -pEnter password: Welcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 2Server version: 5.7.25 MySQL Community Server (GPL)Copyright (c) 2000, 2019, 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)
到此,简单的搭建完成