mysql> SET AUTOCOMMIT=1; # Used for quick re-create of the table
mysql> DELETE FROM pet;
mysql> LOAD DATA LOCAL INFILE "pet.txt" INTO TABLE pet;
.只修正有錯誤的記錄:
mysql> UPDATE pet SET birth = "1989-08-31" WHERE name = "Bowser";
【3.3.4.2選擇特定列】
mysql> SELECT * FROM pet WHERE name = "Bowser";
mysql> SELECT * FROM pet WHERE birth >= "1998-1-1";
mysql> SELECT * FROM pet WHERE species = "dog" AND sex = "f";
mysql> SELECT * FROM pet WHERE species = "snake" OR species = "bird";
mysql> SELECT * FROM pet WHERE (species = "cat" AND sex = "m")
-> OR (species = "dog" AND sex = "f");
【3.3.4.3選擇特定欄】
mysql> SELECT name, birth FROM pet;
mysql> SELECT owner FROM pet;
mysql> SELECT DISTINCT owner FROM pet;
mysql> SELECT name, species, birth FROM pet
-> WHERE species = "dog" OR species = "cat";
【3.3.4.4輸出時依列排序】
mysql> SELECT name, birth FROM pet ORDER BY birth;
mysql> SELECT name, birth FROM pet ORDER BY birth DESC;
mysql> SELECT name, species, birth FROM pet ORDER BY species, birth DESC;
其它SQL指令
DROP
ALTER
INSERT INTO
DELETE
UPDATE
【dump資料表結構與裡面的資料】
mysqldump -u 使用者名稱 -p 密碼 資料庫 [資料表1 [資料表2...]]
備份home資料庫到home20020627.sql檔案
mysqldump -u root -p home > home20020627.sql
備份所有的MySQL資料庫的到backup-file.sql
# mysqldump -p -A > backup-file.sql
【自dump讀回資料】
# mysql -u root -p < backup-file.sql
【更改使用者密碼】
MySQL的預設管理員username是root,預設無密碼
方法一:
shell> mysql -u root mysql
mysql> UPDATE user SET Password=PASSWORD('new_password')
WHERE user='root';
mysql> FLUSH PRIVILEGES;
★方法二:
You can, in MySQL Version 3.22 and above, use the SET PASSWORD statement:
shell> mysql -u root mysql
mysql> SET PASSWORD FOR root=PASSWORD('new_password');
方法三:
Another way to set the password is by using the mysqladmin command:
shell> mysqladmin -u root password new_password
Only users with write/update access to the mysql database can change the password for others users. All normal users (not anonymous ones) can only change their own password with either of the above commands or with SET PASSWORD=PASSWORD('new password').
【新增使用者】
可使用GRANT指令,同時新增使用者與給予權限的工作
GRANT and REVOKE語法
GRANT priv_type [(column_list)] [, priv_type [(column_list)] ...]