使用的命令:mysql_install_db,用于初始化mysql的數(shù)據(jù)庫(kù),生成元數(shù)據(jù)。

創(chuàng)新互聯(lián)建站專注于企業(yè)成都營(yíng)銷網(wǎng)站建設(shè)、網(wǎng)站重做改版、九江網(wǎng)站定制設(shè)計(jì)、自適應(yīng)品牌網(wǎng)站建設(shè)、H5場(chǎng)景定制、商城網(wǎng)站制作、集團(tuán)公司官網(wǎng)建設(shè)、外貿(mào)網(wǎng)站制作、高端網(wǎng)站制作、響應(yīng)式網(wǎng)頁(yè)設(shè)計(jì)等建站業(yè)務(wù),價(jià)格優(yōu)惠性價(jià)比高,為九江等各大城市提供網(wǎng)站開發(fā)制作服務(wù)。
若不加任何參數(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即可
-----------------------------------
開啟MySQL服務(wù)后,使用MySQL命令可以登錄。一般使用mysql -uroot -p即可。如果數(shù)據(jù)庫(kù)不是本機(jī),則需要加參數(shù),常用參數(shù)如下:
1,-h,指定ip地址,默認(rèn)為localhost
2,-u,指定用戶名。
3,-p,指定密碼,密碼可以接在-p后面輸入mysql -uroot -p123456。也也可以mysql -uroot -p回車等提示輸入密碼時(shí)輸入,這樣輸入密碼沒有回顯。
ubuntu下mysql的常用命令,MySQL數(shù)據(jù)庫(kù)的基本操作命令
一、mysql服務(wù)操作
0、查看數(shù)據(jù)庫(kù)版本 sql- status;
1、net start mysql //啟動(dòng)mysql服務(wù)
2、net stop mysql //停止mysql服務(wù)
3、mysql
-h主機(jī)地址 -u用戶名 -p用戶密碼 //進(jìn)入mysql數(shù)據(jù)庫(kù)
4、quit //退出mysql操作
5、mysqladmin -u用戶名
-p舊密碼 password 新密碼 //更改密碼
6、grant select on 數(shù)據(jù)庫(kù).* to 用戶名@登錄主機(jī) identified by
"密碼" //增加新用戶
exemple:
例2、增加一個(gè)用戶test2密碼為abc,讓他只可以在localhost上登錄,并可以對(duì)數(shù)據(jù)庫(kù)mydb進(jìn)行查詢、插入、修改、刪除的操作
(localhost指本地主機(jī),即MYSQL數(shù)據(jù)庫(kù)所在的那臺(tái)主機(jī)),這樣用戶即使用知道test2的密碼,他也無法從internet上直接訪問數(shù)據(jù)
庫(kù),只能通過MYSQL主機(jī)上的web頁(yè)來訪問了。
grant select,insert,update,delete on mydb.* to
test2@localhost identified by "abc";
如果你不想test2有密碼,可以再打一個(gè)命令將密碼消掉。
grant
select,insert,update,delete on mydb.* to test2@localhost identified by "";
二、數(shù)據(jù)庫(kù)操作
1、show databases; //列出數(shù)據(jù)庫(kù)
2、use
database_name //使用database_name數(shù)據(jù)庫(kù)
3、create database data_name
//創(chuàng)建名為data_name的數(shù)據(jù)庫(kù)
4、drop database data_name //刪除一個(gè)名為data_name的數(shù)據(jù)庫(kù)
三、表操作
1、show databases;//列出所有數(shù)據(jù)庫(kù)
use 數(shù)據(jù)庫(kù)名;
//到達(dá)某一數(shù)據(jù)庫(kù)
show tables //列出所有表
create table tab_name(
id int(10)
not null auto_increment primary key,
name varchar(40),
pwd varchar(40)
) charset=gb2312; 創(chuàng)建一個(gè)名為tab_name的新表
2、drop table tab_name
刪除名為tab_name的數(shù)據(jù)表
3、describe tab_name //顯示名為tab_name的表的數(shù)據(jù)結(jié)構(gòu)
4、show
columns from tab_name //同上
5、delete from tab_name //將表tab_name中的記錄清空
6、select * from tab_name //顯示表tab_name中的記錄
7、mysqldump -uUSER -pPASSWORD
--no-data DATABASE TABLE table.sql //復(fù)制表結(jié)構(gòu)
四、修改表結(jié)構(gòu)
1、 ALTER TABLE tab_name ADD PRIMARY KEY (col_name)
說明:更改表得的定義把某個(gè)欄位設(shè)為主鍵。
2、ALTER TABLE tab_name DROP PRIMARY KEY (col_name)
說明:把主鍵的定義刪除
3、 alter table tab_name add col_name varchar(20);
//在tab_name表中增加一個(gè)名為col_name的字段且類型為varchar(20)
4、alter table tab_name drop
col_name //在tab_name中將col_name字段刪除
5、alter table tab_name modify col_name
varchar(40) not null //修改字段屬性,注若加上not null則要求原字段下沒有數(shù)據(jù)
SQL
Server200下的寫法是:Alter Table table_name Alter Column col_name varchar(30) not
null;
6、如何修改表名:alter table tab_name rename to new_tab_name
7、如何修改字段名:alter table tab_name change old_col new_col varchar(40);
//必須為當(dāng)前字段指定數(shù)據(jù)類型等屬性,否則不能修改
8、create table new_tab_name like old_tab_name
//用一個(gè)已存在的表來建新表,但不包含舊表的數(shù)據(jù)
五、數(shù)據(jù)的備份與恢復(fù)
導(dǎo)入外部數(shù)據(jù)文本:
1.執(zhí)行外部的sql腳本
當(dāng)前數(shù)據(jù)庫(kù)上執(zhí)行:mysql input.sql
指定數(shù)據(jù)庫(kù)上執(zhí)行:mysql [表名]
input.sql
2.數(shù)據(jù)傳入命令 load data local infile "[文件名]" into table [表名];
備份數(shù)據(jù)庫(kù):(dos下)
mysqldump --opt schoolschool.bbb
mysqldump -u
[user] -p [password] databasename filename (備份)
mysql -u [user] -p
[password] databasename filename (恢復(fù))
從MSQL官中國(guó)下載MySQL服務(wù)器安裝軟件包,下面以mysql-installer-中國(guó)munity-5.7.3.0-m13.msi為例。 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ù)庫(kù)權(quán)限管理,為遠(yuǎn)程訪問者提供安全賬戶。 12、默認(rèn)windows服務(wù)配置不做修改,點(diǎn)擊“Next”。 13、回到配置概述(Configuration?Overview)界面,安裝完畢點(diǎn)擊“Next”。 14、MySQL安裝完成(Installation?Complete),點(diǎn)擊“Finish”。 15、若勾選“安裝后啟動(dòng)Mysql工作臺(tái)”(Start?Mysql?Workbench?after?Setup),可見如下界面。 注意:MySQL環(huán)境變量配置。 ??? 在windows命令提示符中輸入mysql,提示“mysql”不是內(nèi)部或外部命令。只需將MySQL安裝路徑添加系統(tǒng)環(huán)境變量即可。 ?? ?如安裝路徑為“D:\Program?Files\MySQL”目錄,則進(jìn)入mysql?server的bin目錄下復(fù)制路徑;其次在環(huán)境變量中編輯變量Path,變量值中輸入“;”后粘貼“D:\Program?Files\MySQL\MySQL?Server?5.7\bin”路徑,最后從新打開命令提示符窗口運(yùn)行mysql即可
網(wǎng)站題目:初始化了mysql怎么辦,mysql為什么要初始化
標(biāo)題路徑:http://chinadenli.net/article20/hchdco.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供響應(yīng)式網(wǎng)站、品牌網(wǎng)站設(shè)計(jì)、虛擬主機(jī)、定制網(wǎng)站、網(wǎng)站收錄、做網(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í)需注明來源: 創(chuàng)新互聯(lián)