[root@xiaoxiong ~]# /usr/local/mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/data
2019-08-17T12:12:01.417299Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2019-08-17T12:12:01.805880Z 0 [Warning] InnoDB: New log files created, LSN=45790
2019-08-17T12:12:01.866478Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2019-08-17T12:12:01.925984Z 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: 383208d1-c0e8-11e9-9c5d-000c29676c62.
2019-08-17T12:12:01.926812Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2019-08-17T12:12:01.928903Z 1 [Note] A temporary password is generated for root@localhost: aNhBUsr3,m<<
结尾会生成一个随机密码,保存下来
[root@xiaoxiong ~]# echo "aNhBUsr3,m<<" > pass
生成配置文件
[root@xiaoxiong ~]# cat > /etc/my.cnf <<EOF
> [mysqld]
> basedir = /usr/local/mysql
> datadir = /data
> socket = /tmp/mysql.sock
> port = 3306
> pid-file = /data/mysql.pid
> user = mysql
> skip-name-resolve
> EOF
[root@xiaoxiong ~]# cat /etc/my.cnf
[mysqld]
basedir = /usr/local/mysql
datadir = /data
socket = /tmp/mysql.sock
port = 3306
pid-file = /data/mysql.pid
user = mysql
skip-name-resolve
配置服务启动脚本
[root@xiaoxiong ~]# cp -a /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
[root@xiaoxiong ~]# sed -ri 's#^(basedir=).*#\1/usr/local/mysql#g' /etc/init.d/mysqld
[root@xiaoxiong ~]# sed -ri 's#^(datadir=).*#\1/opt/data#g' /etc/init.d/mysqld
启动mysql服务
[root@xiaoxiong ~]# service mysqld restart
Shutting down MySQL. SUCCESS!
Starting MySQL. SUCCESS!
[root@xiaoxiong ~]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 *:22 *:*
LISTEN 0 100 127.0.0.1:25 *:*
LISTEN 0 128 :::22 :::*
LISTEN 0 100 ::1:25 :::*
LISTEN 0 80 :::3306 :::*
修改密码
利用初始化给的随机密码登陆mysql
[root@xiaoxiong ~]# cat pass
aNhBUsr3,m<<
[root@xiaoxiong ~]# /usr/local/mysql/bin/mysql -uroot -p'aNhBUsr3,m<<''
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.26
Copyright (c) 2000, 2019, 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> set password = password('123456');
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> quit
登陆验证
[root@xiaoxiong ~]# /usr/local/mysql/bin/mysql -uroot -p'123456';
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.26 Source distribution
Copyright (c) 2000, 2019, 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>