mysql初始化怎么執(zhí)行 mysql初始化失敗原因

如何初始化mysql數(shù)據(jù)庫(kù)

初始化mysql數(shù)據(jù)庫(kù),在shell中運(yùn)行以下命令:

天元ssl適用于網(wǎng)站、小程序/APP、API接口等需要進(jìn)行數(shù)據(jù)傳輸應(yīng)用場(chǎng)景,ssl證書(shū)未來(lái)市場(chǎng)廣闊!成為成都創(chuàng)新互聯(lián)公司的ssl證書(shū)銷售渠道,可以享受市場(chǎng)價(jià)格4-6折優(yōu)惠!如果有意向歡迎電話聯(lián)系或者加微信:18982081108(備注:SSL證書(shū)合作)期待與您的合作!

cd /usr/local/mysql

mkdir sock

cd /usr/local/mysql/bin

初始化數(shù)據(jù)庫(kù)

./mysql_install_db--user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data

或者# mysqld --initialize

擴(kuò)展資料

mysql數(shù)據(jù)庫(kù)的備份

1、物理冷備份,需要在數(shù)據(jù)庫(kù)關(guān)閉狀態(tài)下進(jìn)行,能夠較好的保證數(shù)據(jù)庫(kù)的完整性。一般用于非核心業(yè)務(wù),這類業(yè)務(wù)一般都允許終端,物理冷備份的特點(diǎn)就是速度快,恢復(fù)操作簡(jiǎn)單。通常通過(guò)直接打包數(shù)據(jù)庫(kù)文件夾(如:/usr/local/mysql/data)來(lái)實(shí)現(xiàn)

2、通過(guò)啟用二進(jìn)制日志進(jìn)行增量備份,MySQL支持增量備份,進(jìn)行增量備份時(shí)必須啟用二進(jìn)制日志。二進(jìn)制日志文件為用戶提供復(fù)制,對(duì)執(zhí)行備份點(diǎn)后進(jìn)行的數(shù)據(jù)庫(kù)更改所需的信息進(jìn)行恢復(fù)。如果進(jìn)行增量備份,需要刷新二進(jìn)制日志。

參考資料來(lái)源:百度百科—mySQL

啟動(dòng)mysql的docker鏡像,怎么自動(dòng)執(zhí)行初始化sql腳本

在docker中有一個(gè)mysql服務(wù),其數(shù)據(jù)文件是掛在在主機(jī)外面的文件,在docker中的root有訪問(wèn)該數(shù)據(jù)文件的權(quán)限,但是docker中mysql訪問(wèn)數(shù)據(jù)文件的時(shí)候提示權(quán)限不足,于是只有以root用戶來(lái)啟動(dòng)mysql了。

數(shù)據(jù)初始化:

mysql_install_db --user=root --explicit_defaults_for_timestamp=111

初始化后以root用戶啟動(dòng)

mysqld --user=root --explicit_defaults_for_timestamp=111

mysql啟動(dòng)正常。

啟動(dòng)方式主要有以下三種:

1、使用systemctl 啟動(dòng) systemctl start mysqld

2、使用腳本啟動(dòng) /etc/inint.d/mysqld start

3、使用safe_mysqld或mysqld --user=mysql啟動(dòng)

關(guān)閉方式也有以下三種:

1、使用systemctl 關(guān)閉 systemctl stop mysqld

2、使用腳本關(guān)閉 /etc/inint.d/mysqld stop

3、mysqladmin shutdown

注意:使用safe_mysqld或mysqld --user=mysql啟動(dòng)的服務(wù),只能通過(guò)mysqladmin shutdown關(guān)閉,不能通過(guò)systemctl 或腳本關(guān)閉。

mysqladmin shutdown可關(guān)閉以上三種服務(wù)。腳本可關(guān)閉systemctl開(kāi)啟的服務(wù),同樣systemctl也可關(guān)閉腳本開(kāi)

如何初始化mysql數(shù)據(jù)

一、mysql_install_db說(shuō)明

當(dāng)MySQL的系統(tǒng)庫(kù)(mysql系統(tǒng)庫(kù))發(fā)生故障或需要新加一個(gè)mysql實(shí)例時(shí),需要初始化mysql數(shù)據(jù)庫(kù)。

需要使用的命令:/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

除了支持以上的參數(shù),還支持mysqld的參數(shù)。

二、舉例:

本文以新加一個(gè)mysql實(shí)例為例。例如服務(wù)器上已經(jīng)安裝了3306端口的mysql服務(wù),需要再啟一個(gè)3308端口的mysql服務(wù)。

假設(shè)mysql安裝在/usr/local/mysql路徑下,找一個(gè)磁盤空間剩余比較大的盤,如/data1,把3308端口的mysql的數(shù)據(jù)保存在/data1下

#mkdir /data1/mysql_3308

#mkdir /data1/mysql_3308/data

#chown -R mysql:mysql /data1/mysql_3308

復(fù)制一個(gè)mysql配置文件my.cnf到/data1/mysql_3308目錄下

#vi /data1/mysql_3308/my.cnf

修改配置文件,將端口和相關(guān)目錄的都改為新的設(shè)置,如下:

[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

......其他略

確保配置文件無(wú)誤。

運(yùn)行下面命令進(jìn)行數(shù)據(jù)庫(kù)的初始化:

#/usr/local/mysql/bin/mysql_install_db --defaults-file=/data1/mysql_3308/my.cnf --datadir=/data1/mysql_3308/data

完成后新的3308數(shù)據(jù)庫(kù)就初始化好了,如果有報(bào)錯(cuò),則按照?qǐng)?bào)錯(cuò)的提示查看報(bào)錯(cuò)日志,一般情況下都是my.cnf配置文件的問(wèn)題,修正后即可。

三、啟動(dòng)新mysql

啟動(dòng)3308端口的mysql服務(wù)

#/usr/local/mysql/bin/mysqld_safe --defaults-file=/data1/mysql_3309/my.cnf

檢查是否啟動(dòng)

#ps aux|grep mysql

如果有3308字樣說(shuō)明已經(jīng)啟動(dòng)成功

可將啟動(dòng)命令加入/etc/rc.local隨服務(wù)器啟動(dòng)

新加的mysql沒(méi)有設(shè)置root密碼,可以通過(guò)下面命令設(shè)置root密碼:

#/usr/local/mysql/bin/mysqladmin -S /tmp/mysql_3308.sock -u root password 'new-password'

本文標(biāo)題:mysql初始化怎么執(zhí)行 mysql初始化失敗原因
文章出自:http://bm7419.com/article22/dohgpjc.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站收錄網(wǎng)頁(yè)設(shè)計(jì)公司、外貿(mào)建站、品牌網(wǎng)站制作、網(wǎng)站制作、靜態(tài)網(wǎng)站

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

手機(jī)網(wǎng)站建設(shè)