1、命令行連接MySQL數(shù)據(jù)庫(kù):
???
mysql -h host
-u user
-p
??? Enter password:
********
其中 host是MySQL主機(jī)的ip(本機(jī)的話(huà)也可以用localhost),user是你的用戶(hù)名
2、列出服務(wù)器上所有數(shù)據(jù)庫(kù)名稱(chēng):
SHOW DATABASES;
3、模糊比配列出符合條件的數(shù)據(jù)庫(kù)名稱(chēng):SHOW DATABASES LIKE 'my%';
4、設(shè)置默認(rèn)數(shù)據(jù)庫(kù):USE databasename;? 例如:
SELECT?*?FROM?bank.account;
等同于:
USE?bank;
SELECT?*?FROM?account;
也可以在連接時(shí)指定默認(rèn)數(shù)據(jù)庫(kù):
??? ??
mysql -h host
-u user
-p databasename
5、創(chuàng)建數(shù)據(jù)庫(kù):CREATE DATABASE databasename;
??? 刪除數(shù)據(jù)庫(kù):DROP DATABASE databasename;
6、重命名一個(gè)數(shù)據(jù)庫(kù):沒(méi)有直接的命令,可以參照下面的例子(似乎很少碰到這種情況的)
--?Temporarily?disable?permissions
CREATE?DATABASE?library;
RENAME?TABLE?books.book?TO?library.book;
RENAME?TABLE?books.borrower?TO?library.borrower;
RENAME?TABLE?books.loan?TO?library.loan;
--?Migrate?permissions
--?Re-enable?permissions