官網下載tar.gz包
# 創建mysql用戶組和mysql用戶
groupadd mysql
useradd -r -g mysql mysql
# 創建mysql的安裝目錄:/usr/local/mysql,和數據存放目錄:/usr/local/mysql/data
mkdir -p /usr/local/mysql/data
# 解壓縮
tar -zxvf mysql-5.7.24-el7-x86_64.tar.gz
# 更名
mv mysql-5.7.24-el7-x86_64 mysql
# 遷移至安裝目錄
mv mysql /usr/local/
# 移步至安裝目錄
cd /usr/local/mysql/
# 關聯myql用戶到mysql用戶組中
chown -R mysql:mysql /usr/local/mysql
# 給讀寫權限
chmod -R 755 /usr/local/mysql/
# 啓動mysql服務前準備
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
# 分配權限
chmod 755 /etc/init.d/mysqld
# MySQL初始化命令,此初始化操作會在/usr/local/mysql/data 生成相關文件,重新初始化,要刪除這些文件。
/usr/local/mysql/bin/mysqld --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --initialize
2019-04-13T16:02:06.034090Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2019-04-13T16:02:06.558312Z 0 [Warning] InnoDB: New log files created, LSN=45790
2019-04-13T16:02:06.603765Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2019-04-13T16:02:06.676414Z 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: 7c6b48f5-5e05-11e9-95cb-000c293c86b2.
2019-04-13T16:02:06.678082Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2019-04-13T16:02:06.691837Z 1 [Note] A temporary password is generated for root@localhost: yBj%l)ejr0UK
# 啓動MySQL服務
sh /usr/local/mysql/support-files/mysql.server start
# 可能遇見的報錯
[root@localhost bin]# mysql -uroot -pyBj%l)ejr0UK
-bash: syntax error near unexpected token `)'
[root@localhost bin]# mysql -uroot -pyBj%l\)ejr0UK
mysql: [Warning] Using a password on the command line interface can be insecure.
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
[root@localhost bin]# mysql -uroot -p
Enter password:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
[root@localhost bin]#
[root@localhost bin]# mysql -uroot -p
Enter password:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
[root@localhost bin]# cd ..
[root@localhost mysql]# systemctl stop mysqld
Failed to stop mysqld.service: Unit mysqld.service not loaded.
[root@localhost mysql]# ps -ef|grep mysql
root 20625 1 0 Apr13 pts/2 00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/usr/local/mysql/data --pid-file=/usr/local/mysql/data/localhost.localdomain.pid
mysql 20710 20625 1 Apr13 pts/2 00:00:09 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=localhost.localdomain.err --pid-file=/usr/local/mysql/data/localhost.localdomain.pid
root 20827 20369 0 00:04 pts/2 00:00:00 grep --color=auto mysql
[root@localhost mysql]# kill 20625
[root@localhost mysql]# ps -ef|grep mysql
root 20625 1 0 Apr13 pts/2 00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/usr/local/mysql/data --pid-file=/usr/local/mysql/data/localhost.localdomain.pid
mysql 20710 20625 1 Apr13 pts/2 00:00:09 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=localhost.localdomain.err --pid-file=/usr/local/mysql/data/localhost.localdomain.pid
root 20829 20369 0 00:05 pts/2 00:00:00 grep --color=auto mysql
[root@localhost mysql]# kill 20625
[root@localhost mysql]# kill 20625
[root@localhost mysql]# kill 20625
[root@localhost mysql]# kill -9 20625
[root@localhost mysql]# kill -9 20625
-bash: kill: (20625) - No such process
[root@localhost mysql]# ps -ef|grep mysql
mysql 20710 1 1 Apr13 pts/2 00:00:09 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=localhost.localdomain.err --pid-file=/usr/local/mysql/data/localhost.localdomain.pid
root 20853 20369 0 00:05 pts/2 00:00:00 grep --color=auto mysql
[root@localhost mysql]# kill -9 20710
[root@localhost mysql]# ps -ef|grep mysql
root 20855 20369 0 00:05 pts/2 00:00:00 grep --color=auto mysql
[root@localhost mysql]# ls
bin COPYING data docs include lib man README share support-files
[root@localhost mysql]# support-files/mysql.server start
Starting MySQL.Logging to '/usr/local/mysql/data/localhost.localdomain.err'.
.. SUCCESS!
[root@localhost mysql]# mysql -uroot -pyBj%l)ejr0UK
-bash: syntax error near unexpected token `)'
[root@localhost mysql]# mysql -uroot -pyBj%l\)ejr0UK
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 2
Server version: 5.7.24
Copyright (c) 2000, 2018, 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('root');
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> grant all privileges on *.* root@'%' identified by 'root';
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'root@'%' identified by 'root'' at line 1
mysql> grant all privileges on *.* root@'%' identified by 'root';
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'root@'%' identified by 'root'' at line 1
mysql> grant all privileges on *.* to root@'%' identified by 'root';
Query OK, 0 rows affected, 1 warning (0.01 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)
mysql> ^DBye
[root@localhost mysql]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.24 MySQL Community Server (GPL)
Copyright (c) 2000, 2018, 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> show database;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'database' at line 1
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.00 sec)
mysql>