在使用MySQL數據庫過程中,有時候會遇到數據庫重復的問題。本文將介紹MySQL數據庫為什么會出現重復數據庫,并提供解決方案。
MySQL數據庫重復是什么意思?當您在MySQL服務器上安裝多個實例時,每個實例都必須有獨特的名稱。實例名稱是當前運行的MySQL服務和與其關聯的數據目錄的標識符。如果您安裝與現有MySQL實例名稱相同的新實例,則會出現重復數據庫。
$ mysql_install_db --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data Installing MySQL system tables... 191017 10:54:36 [Warning] '--skip-locking' is deprecated and will be removed in a future release. Please use '--skip-external-locking' instead. 191017 10:54:36 [Warning] mysql_install_db is deprecated. Please use mysqld --initialize instead. 191017 10:54:36 [Warning] The syntax '--log' is deprecated and will be removed in a future release. Please use '--general-log[={0|1}]' instead. OK Filling help tables... 191017 10:54:36 [Warning] '--skip-locking' is deprecated and will be removed in a future release. Please use '--skip-external-locking' instead. 191017 10:54:36 [Warning] mysql_install_db is deprecated. Please use mysqld --initialize instead. To start mysqld at boot time you have to copy support-files/mysql.server to the right place for your system PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER ! To do so, start the server, then issue the following commands: /usr/local/mysql/bin/mysqladmin -u root password 'new-password' /usr/local/mysql/bin/mysqladmin -u root -h myhost password 'new-password' See the manual for more instructions. You can start the MySQL daemon with: cd /usr/local/mysql ; /usr/local/mysql/bin/mysqld_safe & You can test the MySQL daemon with mysql-test-run.pl Please report any problems at http://bugs.mysql.com/ The latest information about MySQL is available on the web at http://www.mysql.com Support MySQL by buying support/licenses at http://shop.mysql.com New default config file was created as /usr/local/mysql/my.cnf and will be used by default by the server when you start it. You may edit this file to change server settings WARNING: Default config file /etc/my.cnf exists on the system This file will be read by default by the MySQL server If you do not want to use this, either remove it, or use the --defaults-file argument to mysqld_safe when starting the server
如上所示,當我們在MySQL系統上創建新實例時,我們可以看到警告信息,提示mysql_install_db過時,應改用mysqld --initialize代替。此外,有許多其他選項可用于自定義安裝過程,例如指定MySQL數據目錄的位置等。
為了避免出現重復數據庫,我們應該始終為新實例命名唯一的名稱,并且要確保new-instance-name不與任何其他實例名稱相同。如果在安裝MySQL時沒有為實例指定名稱,則系統將默認創建名為mysql的實例。
$ mysqld --initialize-insecure --datadir=/usr/local/mysql/data --basedir=/usr/local/mysql --socket=/tmp/mysql.sock
除此之外,我們可以通過以下方式來查看MySQL的實例信息:
$ ps aux | grep mysqld
MySQL數據庫中出現重復的問題并不是太難解決。只要我們在創建新實例時記得為實例命名唯一的名稱,并同時確保避免與其他實例名稱相同,就能夠避免重復數據庫的問題。