Enter password: ← 在這里輸入密碼
Welcome to the MySQL monitor. Commands end with ; or \g. ← 確認用密碼能夠成功登錄
Your MySQL connection id is 6 to server version: 4.1.20
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql> exit ← 退出MySQL服務器
Bye
[2] 刪除匿名用戶
在MySQL剛剛被安裝后,存在用戶名、密碼為空的用戶。這使得數據庫服務器有無需密碼被登錄的可能性。為消除隱患,將匿名用戶刪除。
[root@sample ~]# mysql -u root -p ← 通過密碼用root登錄
Enter password: ← 在這里輸入密碼
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 7 to server version: 4.1.20
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql> select user,host from mysql.user; ← 查看用戶信息
+------+----------------------------+
| user | host |
+------+----------------------------+
| | localhost |
| root | localhost |
| | sample.centospub.com |
| root | sample.centospub.com |
+------+----------------------------+
4 rows in set (0.02 sec)
mysql> delete from mysql.user where user=''; ← 刪除匿名用戶
Query OK, 2 rows affected (0.17 sec)
mysql> select user,host from mysql.user; ← 查看用戶信息
+------+----------------------------+
| user | host |
+------+----------------------------+
| root | localhost |
| root | sample.centospub.com |
+------+----------------------------+
2 rows in set (0.00 sec)
mysql> exit ← 退出MySQL服務器
Bye
好了,下面都不是必須的了!
測試MySQL
[root@sample ~]# mysql -u root -p ← 通過密碼用root登錄
Enter password: ← 在這里輸入密碼
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 9 to server version: 4.1.20
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql> grant all privileges on test.* to centospub@localhost identified by '在這里定義密碼'; ← 建立對test數據庫有完全操作權限的名為centospub的用戶
Query OK, 0 rows affected (0.03 sec)
mysql> select user from mysql.user where user='centospub'; ← 確認centospub用戶的存在與否
+---------+
| user |
+---------+
| centospub | ← 確認centospub已經被建立
+---------+
1 row in set (0.01 sec)
mysql> exit ← 退出MySQL服務器
Bye
[root@sample ~]# mysql -u centospub -p ← 用新建立的centospub用戶登錄MySQL服務器
Enter password: ← 在這里輸入密碼
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 10 to server version: 4.1.20
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql> create database test; ← 建立名為test的數據庫
Query OK, 1 row affected (0.00 sec)
mysql> show databases; ← 查看系統已存在的數據庫
+-------------+
| Database |
+-------------+
| test |
+-------------+
1 row in set (0.00 sec)
mysql> use test ← 連接到數據庫
Database changed
mysql> create table test(num int, name varchar(50)); ← 在數據庫中建立表
Query OK, 0 rows affected (0.03 sec)
mysql> show tables; ← 查看數據庫中已存在的表
+-------------------+
| Tables_in_test |
+-------------------+
| test |
+-------------------+
1 row in set (0.01 sec)
mysql> insert into test values(1,'Hello World!'); ← 插入一個值到表中
Query OK, 1 row affected (0.02 sec)
mysql> select * from test; ← 查看數據庫中的表的信息
+------+-------------------+
| num | name |
+------+-------------------+
| 1 | Hello World! |
+------+-------------------+
1 row in set (0.00 sec)
mysql> update test set name='Hello Everyone!'; ← 更新表的信息,賦予新的值
Query OK, 1 row affected (0.00 sec)
原文轉自:http://www.blogjava.net/qileilove/archive/2012/05/24/379016.html