標籤:mysql
設定mysql環境變數[[email protected]~]# echo "PATH=$PATH:/usr/local/mysql/bin" >> /etc/profile[[email protected]~]# source /etc/profile[[email protected]~]# mysql -uroot -p‘passwd‘mysql>查詢當前的庫mysql> show databases;+--------------------+| Database |+--------------------+| information_schema || mysql || test |+--------------------+3 rows in set (0.06 sec)查詢某個庫的表mysql> use mysql;Database changedmysql> show tables;查看某個表的全部欄位mysql> desc slow_log;mysql> show create table slow_log\G;查看當前是哪個使用者mysql> select user();查看當前所使用資料庫mysql> select database();建立一個新庫mysql> create database db1;Query OK, 1 row affected (0.05 sec)建立一個新表mysql> use db1;Database changedmysql> create table t1 (`id` int(4), `name` char(40));Query OK, 0 rows affected (0.02 sec)查看當前資料庫版本mysql> select version();查看當前mysql狀態mysql> show status;查看mysql的參數mysql> show variables;建立一個普通使用者並授權mysql> grant all on *.* to ‘test‘@‘%‘ identified by ‘123‘;Query OK, 0 rows affected (0.01 sec)查詢語句mysql> select count(*) from mysql.user;mysql> select * from mysql.db;mysql> select db from mysql.db;mysql> select db,user from mysql.db;mysql> select * from mysql.db where host like ‘10.0.%‘;插入一行mysql> insert into db1.t1 values (1, ‘abc‘);Query OK, 1 row affected (0.02 sec)mysql> select * from db1.t1;更改表的某一行mysql> update db1.t1 set name=‘aaa‘ where id=1;Query OK, 1 row affected (0.01 sec)Rows matched: 1 Changed: 1 Warnings: 0mysql> select * from db1.t1;清空表資料mysql> truncate table db1.t1;Query OK, 0 rows affected (0.01 sec)mysql> select count(*) from db1.t1;刪除表mysql> drop table db1.t1;Query OK, 0 rows affected (0.00 sec) 刪除資料庫mysql> drop database db1;Query OK, 0 rows affected (0.02 sec)備份:[[email protected] ~]# mysqldump -uroot -p‘yourpassword‘ mysql >/tmp/mysql.sql恢複:[[email protected] ~]# mysql -uroot -p‘yourpassword‘ mysql </tmp/mysql.sql
本文出自 “Linux_Config” 部落格,請務必保留此出處http://jialiang1026.blog.51cto.com/10119067/1632205
Mysql常用操作