linux下mysql命令

一。mysql啓動及修改密碼
啓動
[root@localhost bin]# service mysqld start
Starting MySQL                                             [OK]
[root@localhost bin]# service mysqld stop
Shutting down MySQL.                                       [OK]
[root@localhost bin]# service mysqld restart
MySQL manager or server PID file could not be found!       [FAILED]
Starting MySQL.                                            [OK]
登陸
root用戶的默認密碼是空的,如果已經有密碼了,修改時需要加參數-p
[root@localhost bin]# mysqladmin -u root password 123
[root@localhost bin]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2 to server version: 5.0.18-log
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql>
進去mysql以後還可以修改密碼,
mysql> set password for 'root'@'localhost'=password('1');
Query OK, 0 rows affected (0.01 sec)
mysql> exit;
Bye
注意mysql環境下,命令都需要帶;結束。
增加新用戶
mysql> grant select,insert,update,delete on *.* to test@localhost identified by "123";
Query OK, 0 rows affected (0.03 sec)
 
意思是新增一個用戶test,密碼爲123,權限由查詢,插入,更新,刪除,允許在本地登陸
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
 
刷新權限
二。mysql數據庫方面操作
顯示已有數據庫列表
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| test               |
+--------------------+
3 rows in set (0.02 sec)
顯示指定數據庫中的表
mysql> use mysql;
Database changed
mysql> show tables;
+---------------------------+
| Tables_in_mysql           |
+---------------------------+
| columns_priv              |
| db                        |
| func                      |
| help_category             |
| help_keyword              |
| help_relation             |
| help_topic                |
| host                      |
| proc                      |
| procs_priv                |
| tables_priv               |
| time_zone                 |
| time_zone_leap_second     |
| time_zone_name            |
| time_zone_transition      |
| time_zone_transition_type |
| user                      |
+---------------------------+
17 rows in set (0.01 sec)
顯示錶結構
mysql> describe user;
mysql> create database abc;   //創建數據庫abc
Query OK, 1 row affected (0.01 sec)
mysql> show databases; // 顯示現有數據庫
+--------------------+
| Database           |
+--------------------+
| information_schema |
| abc                |
| mysql              |
| test               |
+--------------------+
4 rows in set (0.02 sec)
mysql> use abc; //使用abc數據庫

Database changed

mysql> create table a(a1 int(4)); //建立表a1
Query OK, 0 rows affected (0.04 sec)
mysql> drop table a; //刪除表
Query OK, 0 rows affected (0.01 sec) 
mysql> drop database abc; //刪除數據庫
Query OK, 1 row affected (0.01 sec)
mysql> delete from a; //清空表
Query OK, 0 rows affected (0.01 sec)
mysql> select * from a;//查詢
Empty set (0.00 sec)
mysql>
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章