開啟MySQL服務(wù)后,使用MySQL命令可以登錄。一般使用mysql -uroot -p即可。如果數(shù)據(jù)庫不是本機,則需要加參數(shù),常用參數(shù)如下:
創(chuàng)新互聯(lián)主營常寧網(wǎng)站建設(shè)的網(wǎng)絡(luò)公司,主營網(wǎng)站建設(shè)方案,成都APP應(yīng)用開發(fā),常寧h5小程序設(shè)計搭建,常寧網(wǎng)站營銷推廣歡迎常寧等地區(qū)企業(yè)咨詢
1,-h,指定ip地址,默認為localhost
2,-u,指定用戶名。
3,-p,指定密碼,密碼可以接在-p后面輸入mysql -uroot -p123456。也也可以mysql -uroot -p回車等提示輸入密碼時輸入,這樣輸入密碼沒有回顯。
一、mysql_install_db說明
當MySQL的系統(tǒng)庫(mysql系統(tǒng)庫)發(fā)生故障或需要新加一個mysql實例時,需要初始化mysql數(shù)據(jù)庫。
需要使用的命令:/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ù)。
二、舉例:
本文以新加一個mysql實例為例。例如服務(wù)器上已經(jīng)安裝了3306端口的mysql服務(wù),需要再啟一個3308端口的mysql服務(wù)。
假設(shè)mysql安裝在/usr/local/mysql路徑下,找一個磁盤空間剩余比較大的盤,如/data1,把3308端口的mysql的數(shù)據(jù)保存在/data1下
#mkdir /data1/mysql_3308
#mkdir /data1/mysql_3308/data
#chown -R mysql:mysql /data1/mysql_3308
復(fù)制一個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
......其他略
確保配置文件無誤。
運行下面命令進行數(shù)據(jù)庫的初始化:
#/usr/local/mysql/bin/mysql_install_db --defaults-file=/data1/mysql_3308/my.cnf --datadir=/data1/mysql_3308/data
完成后新的3308數(shù)據(jù)庫就初始化好了,如果有報錯,則按照報錯的提示查看報錯日志,一般情況下都是my.cnf配置文件的問題,修正后即可。
三、啟動新mysql
啟動3308端口的mysql服務(wù)
#/usr/local/mysql/bin/mysqld_safe --defaults-file=/data1/mysql_3309/my.cnf
檢查是否啟動
#ps aux|grep mysql
如果有3308字樣說明已經(jīng)啟動成功
可將啟動命令加入/etc/rc.local隨服務(wù)器啟動
新加的mysql沒有設(shè)置root密碼,可以通過下面命令設(shè)置root密碼:
#/usr/local/mysql/bin/mysqladmin -S /tmp/mysql_3308.sock -u root password 'new-password'
初始化mysql數(shù)據(jù)庫,在shell中運行以下命令:
cd /usr/local/mysql
mkdir sock
cd /usr/local/mysql/bin
初始化數(shù)據(jù)庫
./mysql_install_db--user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
或者# mysqld --initialize
擴展資料
mysql數(shù)據(jù)庫的備份
1、物理冷備份,需要在數(shù)據(jù)庫關(guān)閉狀態(tài)下進行,能夠較好的保證數(shù)據(jù)庫的完整性。一般用于非核心業(yè)務(wù),這類業(yè)務(wù)一般都允許終端,物理冷備份的特點就是速度快,恢復(fù)操作簡單。通常通過直接打包數(shù)據(jù)庫文件夾(如:/usr/local/mysql/data)來實現(xiàn)
2、通過啟用二進制日志進行增量備份,MySQL支持增量備份,進行增量備份時必須啟用二進制日志。二進制日志文件為用戶提供復(fù)制,對執(zhí)行備份點后進行的數(shù)據(jù)庫更改所需的信息進行恢復(fù)。如果進行增量備份,需要刷新二進制日志。
參考資料來源:百度百科—mySQL
1.生成授權(quán)表實際上是完成了mysql的初始化。你在執(zhí)行這個腳本之后,mysql里就會出現(xiàn)名為mysql的庫。mysql庫里有常用的權(quán)限表等系統(tǒng)表。比如設(shè)置用戶權(quán)限的user表。
2.后面的參數(shù)--user所指定的用戶是你想要運行mysqld進程用戶名。這個是可變的,不一定非要是mysql。設(shè)置這個用戶以后,所有通過mysqld進程創(chuàng)建的文件都會屬于這個用戶。網(wǎng)上的教程里多用mysql用戶是為了在生產(chǎn)環(huán)境中更方便管理。
不知道這樣說你能不能明白。歡迎追問。
1、停止mysql服務(wù)
2、刪除mysql的data目錄下的,除mysql這個目錄外的其他目錄(為保險期間,先移走)
3、重啟myql即可
-----------------------------------
呵呵,放松,一切都會好起來的!
./mysql_install_db --user=mysql --basedir=/app/mysql --datadir=/app/mysql/data/ --explicit_defaults_for_timestamp
本文名稱:初始化了mysql怎么辦 mysql數(shù)據(jù)初始化命令
網(wǎng)站鏈接:http://chinadenli.net/article32/dodiepc.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供虛擬主機、動態(tài)網(wǎng)站、網(wǎng)站內(nèi)鏈、網(wǎng)站收錄、企業(yè)網(wǎng)站制作、企業(yè)建站
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)