ubuntu18.04手動安裝二進位制MySQL8.0
阿新 • • 發佈:2019-01-14
wget https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-8.0.13-linux-glibc2.12-x86_64.tar.xz
tar xvJf mysql-8.0.13-linux-glibc2.12-x86_64.tar.xz
sudo mv mysql-8.0.13-linux-glibc2.12-x86_64 /var/mysql
然後新建一個檔案/var/mysql/data_3306/my.cnf
:
[mysqld] port=3306 datadir=/var/mysql/data_3306 log_error=/var/mysql/data_3306/error.log basedir=/var/mysql
然後執行如下命令啟動MySQL服務:
var/mysql/bin/mysqld --defaults-file=/var/mysql/data_3306/my.cnf --initialize --user=mysql
發現出錯了,報錯資訊如下:
[email protected]:/var/mysql/data_3306$ cat error.log 2019-01-14T10:59:46.054629Z 0 [Warning] [MY-010139] [Server] Changed limits: max_open_files: 1024 (requested 8161) 2019-01-14T10:59:46.054690Z 0 [Warning] [MY-010142] [Server] Changed limits: table_open_cache: 431 (requested 4000) 2019-01-14T10:59:46.054946Z 0 [System] [MY-013169] [Server] /var/mysql/bin/mysqld (mysqld 8.0.13) initializing of server in progress as process 3621 2019-01-14T10:59:46.056585Z 0 [ERROR] [MY-010457] [Server] --initialize specified but the data directory has files in it. Aborting. 2019-01-14T10:59:46.056652Z 0 [ERROR] [MY-013236] [Server] Newly created data directory /var/mysql/data_3306/ is unusable. You can safely remove it. 2019-01-14T10:59:46.056661Z 0 [ERROR] [MY-010119] [Server] Aborting 2019-01-14T10:59:46.056743Z 0 [System] [MY-010910] [Server] /var/mysql/bin/mysqld: Shutdown complete (mysqld 8.0.13) MySQL Community Server - GPL. 2019-01-14T11:02:07.365206Z 0 [Warning] [MY-010139] [Server] Changed limits: max_open_files: 1024 (requested 8161) 2019-01-14T11:02:07.365266Z 0 [Warning] [MY-010142] [Server] Changed limits: table_open_cache: 431 (requested 4000) 2019-01-14T11:02:07.365524Z 0 [System] [MY-013169] [Server] /var/mysql/bin/mysqld (mysqld 8.0.13) initializing of server in progress as process 3660 2019-01-14T11:02:07.367698Z 0 [ERROR] [MY-010457] [Server] --initialize specified but the data directory has files in it. Aborting. 2019-01-14T11:02:07.367779Z 0 [ERROR] [MY-013236] [Server] Newly created data directory /var/mysql/data_3306/ is unusable. You can safely remove it. 2019-01-14T11:02:07.367797Z 0 [ERROR] [MY-010119] [Server] Aborting 2019-01-14T11:02:07.368023Z 0 [System] [MY-010910] [Server] /var/mysql/bin/mysqld: Shutdown complete (mysqld 8.0.13) MySQL Community Server - GPL. 2019-01-14T11:02:25.091876Z 0 [Warning] [MY-010139] [Server] Changed limits: max_open_files: 1024 (requested 8161) 2019-01-14T11:02:25.091947Z 0 [Warning] [MY-010142] [Server] Changed limits: table_open_cache: 431 (requested 4000) 2019-01-14T11:02:25.092216Z 0 [System] [MY-013169] [Server] /var/mysql/bin/mysqld (mysqld 8.0.13) initializing of server in progress as process 3661 2019-01-14T11:02:25.093893Z 0 [ERROR] [MY-010457] [Server] --initialize specified but the data directory has files in it. Aborting. 2019-01-14T11:02:25.093941Z 0 [ERROR] [MY-013236] [Server] Newly created data directory /var/mysql/data_3306/ is unusable. You can safely remove it. 2019-01-14T11:02:25.093951Z 0 [ERROR] [MY-010119] [Server] Aborting 2019-01-14T11:02:25.094040Z 0 [System] [MY-010910] [Server] /var/mysql/bin/mysqld: Shutdown complete (mysqld 8.0.13) MySQL Community Server - GPL. 2019-01-14T11:03:34.555652Z 0 [Warning] [MY-010139] [Server] Changed limits: max_open_files: 1024 (requested 8161) 2019-01-14T11:03:34.555710Z 0 [Warning] [MY-010142] [Server] Changed limits: table_open_cache: 431 (requested 4000) 2019-01-14T11:03:34.555964Z 0 [System] [MY-013169] [Server] /var/mysql/bin/mysqld (mysqld 8.0.13) initializing of server in progress as process 3676 2019-01-14T11:03:34.557598Z 0 [ERROR] [MY-010457] [Server] --initialize specified but the data directory has files in it. Aborting. 2019-01-14T11:03:34.557644Z 0 [ERROR] [MY-013236] [Server] Newly created data directory /var/mysql/data_3306/ is unusable. You can safely remove it. 2019-01-14T11:03:34.557654Z 0 [ERROR] [MY-010119] [Server] Aborting 2019-01-14T11:03:34.557738Z 0 [System] [MY-010910] [Server] /var/mysql/bin/mysqld: Shutdown complete (mysqld 8.0.13) MySQL Community Server - GPL.
發現是因為datadir對應的目錄裡面有檔案的原因造成的,修改一下datadir引數,my.cnf資訊如下:
[mysqld]
port=3306
datadir=/var/mysql/data_3306
log_error=/var/mysql/data_3306/error.log
basedir=/var/mysql
發現執行成功(通過echo $?
判斷)。
然後啟動mysqld服務:
var/mysql/bin/mysqld --defaults-file=/var/mysql/data_3306/my.cnf --user=mysql
執行之後,在目錄/var/mysql/data_3306/data/
中生成的目錄及檔案如下:
[email protected]:/var/mysql/data_3306$ ls -l /var/mysql/data_3306/data/
總用量 155712
-rw-r----- 1 zifeiy zifeiy 56 1月 14 19:06 auto.cnf
-rw------- 1 zifeiy zifeiy 1676 1月 14 19:06 ca-key.pem
-rw-r--r-- 1 zifeiy zifeiy 1112 1月 14 19:06 ca.pem
-rw-r--r-- 1 zifeiy zifeiy 1112 1月 14 19:06 client-cert.pem
-rw------- 1 zifeiy zifeiy 1676 1月 14 19:06 client-key.pem
-rw-r----- 1 zifeiy zifeiy 5785 1月 14 19:06 ib_buffer_pool
-rw-r----- 1 zifeiy zifeiy 12582912 1月 14 19:06 ibdata1
-rw-r----- 1 zifeiy zifeiy 50331648 1月 14 19:06 ib_logfile0
-rw-r----- 1 zifeiy zifeiy 50331648 1月 14 19:06 ib_logfile1
drwxr-x--- 2 zifeiy zifeiy 4096 1月 14 19:06 '#innodb_temp'
drwxr-x--- 2 zifeiy zifeiy 4096 1月 14 19:06 mysql
-rw-r----- 1 zifeiy zifeiy 25165824 1月 14 19:06 mysql.ibd
drwxr-x--- 2 zifeiy zifeiy 4096 1月 14 19:06 performance_schema
-rw------- 1 zifeiy zifeiy 1676 1月 14 19:06 private_key.pem
-rw-r--r-- 1 zifeiy zifeiy 452 1月 14 19:06 public_key.pem
-rw-r--r-- 1 zifeiy zifeiy 1112 1月 14 19:06 server-cert.pem
-rw------- 1 zifeiy zifeiy 1676 1月 14 19:06 server-key.pem
drwxr-x--- 2 zifeiy zifeiy 4096 1月 14 19:06 sys
-rw-r----- 1 zifeiy zifeiy 10485760 1月 14 19:06 undo_001
-rw-r----- 1 zifeiy zifeiy 10485760 1月 14 19:06 undo_002
一開始使用
/var/mysql/bin/mysql -uroot -h127.0.0.1 -P3306
登陸MySQL彙報錯:
[email protected]:/var/mysql/data_3306$ /var/mysql/bin/mysql -uroot -h127.0.0.1 -P3306
ERROR 2003 (HY000): Can't connect to MySQL server on '127.0.0.1' (111)
但是我們可以在/var/mysql/data_3306/error.log
中看到MySQL伺服器提供給我們的臨時登陸密碼:
[email protected]:/var/mysql/data_3306$ tail -n 2 /var/mysql/data_3306/error.log
2019-01-14T11:06:47.744852Z 5 [Note] [MY-010454] [Server] A temporary password is generated for [email protected]: *C4gk*8%3lwf
2019-01-14T11:06:48.411733Z 0 [System] [MY-013170] [Server] /var/mysql/bin/mysqld (mysqld 8.0.13) initializing of server has completed
重新登陸,發現登陸成功:
[email protected]:/var/mysql/bin$ ./mysql -uroot -h127.0.0.1 -P3306 -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 8.0.13
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>
趕快修改密碼(我這裡改成password
):
alter user 'root'@'localhost' identified by 'password';
為了方便,可以新建一個指令碼檔案~/start_mysqld.sh
,如下:
echo "/var/mysql/bin/mysqld --defaults-file=/var/mysql/data_3306/my.cnf --user=mysql" > ~/start_mysqld.sh
chmod a+x ~/start_mysqld.sh
以後就可以通過bash ~/start_mysqld.sh
來執行mysqld服務了。