匿名使用者
1級2016-10-29 回答
一、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初始化
port 3306 設定mysql的安裝目錄 basedir d php apmw mysql 8.0.17 設定mysql資料庫的資料的存放目錄 datadir d php apmw mysql 8.0.17 data 允許最大連線數 max connections 200 允許連線失敗的次數。m...
mysql 初始化序列 mysql初始化
mysqld nt remove mysql mysqld nt install mysqld initialize insecure user mysql mysqld install mysql root使用者拒絕連線 建立my.ini放在bin下 mysqld 設定3306埠 port 330...
mysql 初始化 mysql時間初始化
date forma t date,format 根據格式串format 格式化日期或日期和時間值date,返回結果串。可用date format 來格式化date 或datetime 值,以便得到所希望的格式。根據format字串格式化date值 s,s 兩位數字形式的秒 00,01,59 i 兩...