一、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'
MySQL數據庫的初始化mysql_install_db
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.