十年網(wǎng)站開發(fā)經(jīng)驗(yàn) + 多家企業(yè)客戶 + 靠譜的建站團(tuán)隊(duì)
量身定制 + 運(yùn)營(yíng)維護(hù)+專業(yè)推廣+無憂售后,網(wǎng)站問題一站解決
當(dāng)在Ubuntu中執(zhí)行命令sudo apt-get install mysql-server5.1安裝的時(shí)候居然沒有提示我輸入mysql的密碼之類的信息,但是當(dāng)安裝好之后再終端中直接輸入mysql的時(shí)候又能直接進(jìn)入mysql中,雖然可以進(jìn)入mysql中但是我對(duì)mysql的密碼一點(diǎn)都不知道,所以這個(gè)時(shí)候安裝的mysql就相當(dāng)于沒有安裝,因?yàn)椴荒苡贸绦蜻M(jìn)行操作mysql數(shù)據(jù)庫(因?yàn)椴僮鲾?shù)據(jù)庫都需要mysql數(shù)據(jù)的密碼的),為了解決ubuntu中mysql密碼初始化的方法有一下兩種:
成都創(chuàng)新互聯(lián)是一家專業(yè)提供濮陽企業(yè)網(wǎng)站建設(shè),專注與網(wǎng)站設(shè)計(jì)制作、網(wǎng)站設(shè)計(jì)、H5場(chǎng)景定制、小程序制作等業(yè)務(wù)。10年已為濮陽眾多企業(yè)、政府機(jī)構(gòu)等服務(wù)。創(chuàng)新互聯(lián)專業(yè)網(wǎng)站設(shè)計(jì)公司優(yōu)惠進(jìn)行中。
(1)打開/etc/mysql/debian.cnf文件,在這個(gè)文件中有系統(tǒng)默認(rèn)給我們分配的用戶名和密碼,通過這個(gè)密碼就可以直接對(duì)mysql進(jìn)行操作了。但是一般這個(gè)密碼都比較怪,很長(zhǎng)很長(zhǎng)。
(2)當(dāng)進(jìn)入mysql之后修改mysql的密碼:這個(gè)方法比較好,具體的操作如下用命令:set password for 'root'@'localhost' = password('yourpass');當(dāng)修改之后就可應(yīng)正常對(duì)mysql進(jìn)行操作了。
使用的命令:mysql_install_db,用于初始化mysql的數(shù)據(jù)庫,生成元數(shù)據(jù)。
若不加任何參數(shù),則該命令按照/etc/my.cnf文件配置執(zhí)行初始化工作,否則可參照如下幫助手動(dòng)執(zhí)行參數(shù)。
$ 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.
1、停止mysql服務(wù)
2、刪除mysql的data目錄下的,除mysql這個(gè)目錄外的其他目錄(為保險(xiǎn)期間,先移走)
3、重啟myql即可
-----------------------------------
呵呵,放松,一切都會(huì)好起來的!
mysql安裝步驟win10:
1、雙擊mysql-installer-community-5.7.20.0.msi安裝包;
2、勾選 Iaccept the license terms,點(diǎn)擊Next按鈕;
3、選擇Server only,點(diǎn)擊Next選項(xiàng)(因?yàn)槲抑幌氚惭b個(gè)服務(wù)器端,所以選了這個(gè)選項(xiàng)。如果想安裝所有的,請(qǐng)選擇full選項(xiàng),如果自定義安裝請(qǐng)選擇Custom選項(xiàng));
4、點(diǎn)擊Execute選項(xiàng)執(zhí)行安裝;
5、安裝的過程中,在Progress列中可以看到安裝進(jìn)度;
6、status列變?yōu)镃omplete說明安裝完成,點(diǎn)擊Next按鈕;
7、點(diǎn)擊Next,進(jìn)行產(chǎn)品配置;
8、這個(gè)保持默認(rèn)選項(xiàng),點(diǎn)擊Next;
9、選擇默認(rèn)選項(xiàng),Development Machine選項(xiàng)會(huì)使用最小的內(nèi)存分配(因?yàn)槭莻€(gè)人練習(xí)使用,所以不用占用太多電腦內(nèi)存),點(diǎn)擊Next;
10、設(shè)置root用戶的口令(我這里設(shè)置的比較簡(jiǎn)單,所以提示密碼比較弱,從安全的角度說,大家還是應(yīng)該把密碼設(shè)置的復(fù)雜一點(diǎn)),點(diǎn)擊Next按鈕;
11、默認(rèn)配置,點(diǎn)擊Next按鈕;
12、插件和擴(kuò)展這保持默認(rèn)選項(xiàng)就好,點(diǎn)擊Next按鈕;
13、點(diǎn)擊Execute按鈕執(zhí)行配置;
14、看到所有都是對(duì)號(hào),說明配置成功,點(diǎn)擊Finish按鈕;
15、再點(diǎn)擊Finish按鈕完成安裝;
16、點(diǎn)擊開始菜單中的MySQL 5.7 Command Line Client 客戶端;
17、輸入安裝時(shí)設(shè)置的root的口令,按下回車;
18、連接成功。
1、雙擊進(jìn)入安裝 2、在協(xié)議許可(License Agreement)界面,勾選“I accept the license terms”,點(diǎn)擊“Next”。 3、在檢查更新信息(Find latest products)界面,勾選“Skip the check for updates(no re中國(guó)mended)”跳過檢查,然后點(diǎn)擊“Next”。 4、在選擇安裝類型(Choosing a Setup Type)界面,根據(jù)安裝需求選擇安裝類型(推薦默認(rèn)開發(fā)版本),設(shè)置MySQL安裝路徑和數(shù)據(jù)存放路徑,最后點(diǎn)擊“Next”。 5、在檢查要求(Check Requirements)界面,點(diǎn)擊“Next”。 6、安裝進(jìn)度(Installation progress)界面,點(diǎn)擊“Execute”執(zhí)行。 7、等待安裝進(jìn)度完畢,點(diǎn)擊“Next”。 8、進(jìn)入配置概述(Configuration Overview)界面,點(diǎn)擊“Next”。 9、在MySQL服務(wù)配置(MySQL Server Configuration)界面,默認(rèn)不做修改,點(diǎn)擊“Next”。 10、設(shè)置根賬戶(root賬戶)密碼。 11、添加(非根)用戶賬戶。其目的是便于數(shù)據(jù)庫權(quán)限管理,為遠(yuǎn)程訪問者提供安全賬戶。
一、mysql_install_db說明
當(dāng)MySQL的系統(tǒng)庫(mysql系統(tǒng)庫)發(fā)生故障或需要新加一個(gè)mysql實(shí)例時(shí),需要初始化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ù)。
二、舉例:
本文以新加一個(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
......其他略
確保配置文件無誤。
運(yùn)行下面命令進(jìn)行數(shù)據(jù)庫的初始化:
#/usr/local/mysql/bin/mysql_install_db --defaults-file=/data1/mysql_3308/my.cnf --datadir=/data1/mysql_3308/data
完成后新的3308數(shù)據(jù)庫就初始化好了,如果有報(bào)錯(cuò),則按照?qǐng)?bào)錯(cuò)的提示查看報(bào)錯(cuò)日志,一般情況下都是my.cnf配置文件的問題,修正后即可。
三、啟動(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字樣說明已經(jīng)啟動(dòng)成功
可將啟動(dòng)命令加入/etc/rc.local隨服務(wù)器啟動(dòng)
新加的mysql沒有設(shè)置root密碼,可以通過下面命令設(shè)置root密碼:
#/usr/local/mysql/bin/mysqladmin -S /tmp/mysql_3308.sock -u root password 'new-password'