五種常用的MySQL命令行
MySQL命令行對我們使用MySQL數(shù)據(jù)庫起到了很大的幫助作用,下面就為您介紹五種常用的MySQL命令行用法,供您參考學(xué)習(xí)。
1.[不同端口登錄]
通過開始菜單-> 程序-> MySQL-> MySQL Command Line Client
通過輸入密碼Enter password:******進(jìn)行登錄 該MySQL服務(wù)端口已定
或者
通過運(yùn)行命令->C:\Program Files\MySQL\MySQL Server 5.2\bin>
然后利用mysql進(jìn)行登錄
C:\Program Files\MySQL\MySQL Server 5.2\bin>mysql -uroot -h127.0.0.1 -P3307 -p
Enter password:******
亦可選擇登錄遠(yuǎn)程MySQL
2.[執(zhí)行SQL文件]
創(chuàng)建測試數(shù)據(jù)庫及數(shù)據(jù)表
mysql> source c:/test/test.sql;
test.sql文件內(nèi)容:
create database IF NOT EXISTS testdb;
use testdb;
create table testtable
(testName varchar(10));
3.[創(chuàng)建用戶]
mysql> create user testuser identified by 'testpass';
4.[賦予權(quán)限]
mysql> grant all privileges on testdb.* to 'testuser'@'%' identified by 'testpass';
5.[修改root密碼]
如果已登錄
1)use mysql
2)update user set password=password('你的密碼') where user='root';
3)flush privileges;
如果沒登錄,你想進(jìn)數(shù)據(jù)庫而沒有密碼
先關(guān)掉服務(wù)
然后以safe模式進(jìn)入
mysqld_safe --skip-grant-tables &
這個(gè)窗口不要關(guān),這樣進(jìn)數(shù)據(jù)庫就不用密碼,進(jìn)去后做 “如果已登錄”的步驟。
【編輯推薦】