- 1、本次搭建mysql數據,選擇了是和mysql類似的MariaDB,完全可以滿足日常的使用需求,且命令和mysql沒有太大的區別。
對應MariaDB下載地址:https://downloads.mariadb.org/
下載的文件:
- 2、解壓下載完成的文件,這里我解壓到了D盤,路徑:D:\mariadb-10.4.7-winx64
- 3、使用win+R,輸入CDM,進入DOS控制台。輸入命令cd D:\mariadb-10.4.7-winx64 ,進入MariaDB的對應的路徑中
如圖所示:
- 4、執行安裝的命令:
mysqld.exe --install MariaDB
注: 如果執行以上的安裝命令出現錯誤,請使用管理員的身份打開cmd
- 5、開啟服務與關閉服務的命令:
net start MariaDB #開啟服務
net stop MariaDB #停止服務
此時容易出現一些錯誤,筆者這里就出現了1067的錯誤信息:
D:\mariadb-10.4.7-winx64\bin>net start MariaDB mariadb 服務正在啟動 ... mariadb 服務無法啟動。 系統出錯。 發生系統錯誤 1067。 進程意外終止。
嘗試了一些方法
進入到Mariadb的文件夾,data下面會有一個文件:主機名.err ,如下圖
使用文本格式打開該文件,即可查看到對應的錯誤信息,類似:
……
InnoDB: using atomic writes. 2019-08-23 10:50:16 0 [Note] InnoDB: Mutexes and rw_locks use Windows interlocked functions 2019-08-23 10:50:16 0 [Note] InnoDB: Uses event mutexes 2019-08-23 10:50:16 0 [Note] InnoDB: Compressed tables use zlib 1.2.11 2019-08-23 10:50:16 0 [Note] InnoDB: Number of pools: 1 2019-08-23 10:50:16 0 [Note] InnoDB: Using SSE2 crc32 instructions 2019-08-23 10:50:16 0 [Note] InnoDB: Initializing buffer pool, total size = 128M, instances = 1, chunk size = 128M 2019-08-23 10:50:16 0 [Note] InnoDB: Completed initialization of buffer pool 2019-08-23 10:50:16 0 [Note] InnoDB: 128 out of 128 rollback segments are active. 2019-08-23 10:50:16 0 [Note] InnoDB: Creating shared tablespace for temporary tables 2019-08-23 10:50:16 0 [Note] InnoDB: Setting file '.\ibtmp1' size to 12 MB. Physically writing the file full; Please wait ... 2019-08-23 10:50:16 0 [Note] InnoDB: File '.\ibtmp1' size is now 12 MB. 2019-08-23 10:50:16 0 [Note] InnoDB: Waiting for purge to start 2019-08-23 10:50:16 0 [Note] InnoDB: 10.4.7 started; log sequence number 113910; transaction id 9 2019-08-23 10:50:16 0 [Note] InnoDB: Loading buffer pool(s) from D:\mariadb-10.4.7-winx64\data\ib_buffer_pool 2019-08-23 10:50:16 0 [Note] Plugin 'FEEDBACK' is disabled. 2019-08-23 10:50:16 0 [ERROR] Could not open mysql.plugin table. Some plugins may be not loaded 2019-08-23 10:50:16 0 [Note] InnoDB: Buffer pool(s) load completed at 190823 10:50:16 2019-08-23 10:50:16 0 [ERROR] Can't open and lock privilege tables: Table 'mysql.servers' doesn't exist 2019-08-23 10:50:16 0 [Note] Server socket created on IP: '::'. 2019-08-23 10:50:16 0 [ERROR] Fatal error: Can't open and lock privilege tables: Table 'mysql.db' doesn't exist 2019-08-23 10:50:16 0 [ERROR] Aborting
筆者這里解決的辦法: 初始化mysql:mysql_install_db
D:\mariadb-10.4.7-winx64\bin>mysql_install_db Default data directory is D:\mariadb-10.4.7-winx64\data Running bootstrap 2019-08-23 10:51:36 0 [Note] D:\mariadb-10.4.7-winx64\bin\mysqld.exe (mysqld 10.4.7-MariaDB) starting as process 15452 ... Removing default user Creating my.ini file Creation of the database was successful
執行以上的命令后,系統會在MariaDb安裝文件下的data生成對應的文件。然后再次執行啟動服務:
D:\mariadb-10.4.7-winx64\bin>net start MariaDB mariadb 服務正在啟動 . mariadb 服務已經啟動成功。
- 6、在CMD窗口,對應MariaDB的bin目錄中執行:mysql -u root -p,如下:輸入密碼時,直接Enter,直接進入MariaDM模式
D:\mariadb-10.4.7-winx64\bin>mysql -u root -p Enter password: Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 9 Server version: 10.4.7-MariaDB mariadb.org binary distribution Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. MariaDB [(none)]>
- 7、由於新的數據庫是沒有密碼的,所以需要進行設置密碼的操作命令:SET PASSWORD FOR 'root'@'localhost' = PASSWORD('root');
如下:
MariaDB [(none)]> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('root');); Query OK, 0 rows affected (0.001 sec)
注:紅色的字體代表,需要增加的密碼。筆者這里設置數據庫密碼是root。
8、可以通過mysql shell的命名查MariaDB數據庫的庫名信息:
D:\mariadb-10.4.7-winx64\bin>mysql -u root -p
Enter password: ****
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 10
Server version: 10.4.7-MariaDB mariadb.org binary distribution
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> show databases
-> ;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
+--------------------+
4 rows in set (0.001 sec)