MySQL資料庫的初始化mysql_install_db

來源:互聯網
上載者:User

一、mysql_install_db說明
當MySQL的系統庫(mysql系統庫)發生故障或需要新加一個mysql執行個體時,需要初始化mysql資料庫。
需要使用的命令:/usr/local/mysql/bin/mysql_install_db
#/usr/local/mysql/bin/mysql_install_db --help 可以查看協助資訊如下
Usage: /usr/local/mysql/bin/mysql_install_db [OPTIONS]
  --basedir=path       The path to the MySQL installation directory.
  --cross-bootstrap    For internal use.  Used when building the MySQL system
                       tables on a different host than the target.
  --datadir=path       The path to the MySQL data directory.
  --force              Causes mysql_install_db to run even if DNS does not
                       work.  In that case, grant table entries that normally
                       use hostnames will use IP addresses.
  --ldata=path         The path to the MySQL data directory.
  --rpm                For internal use.  This option is used by RPM files
                       during the MySQL installation process.
  --skip-name-resolve  Use IP addresses rather than hostnames when creating
                       grant table entries.  This option can be useful if
                       your DNS does not work.
  --srcdir=path        For internal use.  The directory under which
                       mysql_install_db looks for support files such as the
                       error message file and the file for popoulating the
                       help tables.
  --user=user_name     The login username to use for running mysqld.  Files
                       and directories created by mysqld will be owned by this
                       user.  You must be root to use this option.  By default
                       mysqld runs using your current login name and files and
                       directories that it creates will be owned by you.

All other options are passed to the mysqld program
除了支援以上的參數,還支援mysqld的參數。

二、舉例:
   本文以新加一個mysql執行個體為例。例如伺服器上已經安裝了3306連接埠的mysql服務,需要再啟一個3308連接埠的mysql服務。
   假設mysql安裝在/usr/local/mysql路徑下,找一個磁碟空間剩餘比較大的盤,如/data1,把3308連接埠的mysql的資料儲存在/data1下
#mkdir /data1/mysql_3308
#mkdir /data1/mysql_3308/data
#chown -R mysql:mysql /data1/mysql_3308
 
   複製一個mysql設定檔my.cnf到/data1/mysql_3308目錄下
#vi /data1/mysql_3308/my.cnf
修改設定檔,將連接埠和相關目錄的都改為新的設定,如下:
[client]
character-set-server = utf8
port    = 3308
socket  = /tmp/mysql_3308.sock

[mysqld]
user    = mysql
port    = 3308
socket  = /tmp/mysql_3308.sock
basedir = /usr/local/mysql
datadir = /data1/mysql_3308/data
log-error = /data1/mysql_3308/mysql_error.log
pid-file = /data1/mysql_3308/mysql.pid
......其他略

  確保設定檔無誤。
運行下面命令進行資料庫的初始化:
#/usr/local/mysql/bin/mysql_install_db --defaults-file=/data1/mysql_3308/my.cnf --datadir=/data1/mysql_3308/data

完成後新的3308資料庫就初始化好了,如果有報錯,則按照報錯的提示查看報錯日誌,一般情況下都是my.cnf設定檔的問題,修正後即可。

三、啟動新mysql
啟動3308連接埠的mysql服務
#/usr/local/mysql/bin/mysqld_safe --defaults-file=/data1/mysql_3309/my.cnf &
檢查是否啟動
#ps aux|grep mysql
如果有3308字樣說明已經啟動成功
可將啟動命令加入/etc/rc.local隨伺服器啟動

新加的mysql沒有設定root密碼,可以通過下面命令設定root密碼:
#/usr/local/mysql/bin/mysqladmin -S /tmp/mysql_3308.sock -u root password 'new-password'

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.