[root@modue-200 ~]# id mysql
id: mysql: no such user
[root@modue-200 ~]# useradd -r -M -s /sbin/nologin mysql
[root@modue-200 ~]# mkdir /data/mysql/data -p
[root@modue-200 ~]# chown -R mysql.mysql /data
5. 初始化程序
[root@modue-200 ~]# /data/mysql/bin/mysqld --initialize-insecure --user=mysql --basedir=/data/mysql --datadir=/data/mysql/data
2019-05-15T19:01:21.199898Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2019-05-15T19:01:22.604720Z 0 [Warning] InnoDB: New log files created, LSN=45790
2019-05-15T19:01:22.824670Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2019-05-15T19:01:22.907597Z 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: d4d9e940-7743-11e9-bab7-000c292e3374.
2019-05-15T19:01:22.909114Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2019-05-15T19:01:22.910833Z 1 [Warning] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.
[root@modue-200 ~]# cat /etc/systemd/system/mysqld.service
[Unit]
Description=MySQL Server
Documentation=man:mysqld(8)
Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.html
After=network.target
After=syslog.target
[Install]
WantedBy=multi-user.target
[Service]
User=mysql
Group=mysql
ExecStart=/data/mysql/bin/mysqld --defaults-file=/etc/my.cnf
LimitNOFILE = 5000
[root@modue-200 ~]# systemctl start mysqld.service
[root@modue-200 ~]# systemctl status mysqld.service
● mysqld.service - MySQL Server
Loaded: loaded (/etc/systemd/system/mysqld.service; disabled; vendor preset: disabled)
Active: active (running) since Thu 2019-05-16 03:14:15 CST; 12s ago
Docs: man:mysqld(8)
http://dev.mysql.com/doc/refman/en/using-systemd.html
Main PID: 7429 (mysqld)
CGroup: /system.slice/mysqld.service
└─7429 /data/mysql/bin/mysqld --defaults-file=/etc/my.cnf
7. 登錄mysql以及修改密碼
[root@modue-200 ~]# mysql
mysql> exit
[root@modue-200 ~]# mysqladmin -u root -p password 123
Enter password:
mysqladmin: [Warning] Using a password on the command line interface can be insecure.
Warning: Since password will be sent to server in plain text, use ssl connection to ensure password safety.
[root@modue-200 ~]# mysql -u root -p123
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 5
Server version: 5.7.20 MySQL Community Server (GPL)
Copyright (c) 2000, 2017, 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> ^DBye
[root@modue-200 ~]#