MYSQL數據庫操作常用命令
1、MySQL常用命令
create database name; 創建數據庫
use databasename; 選擇數據庫
drop database name 直接刪除數據庫,不提醒
show tables; 顯示表
describe tablename; 表的詳細描述
select * from tablename;
Mysql命令查詢一個表的記錄總數(三種方法)
select count(*) from tablename;
或者
select count(*) as num from tablename;
或者
select count(*) as total from tablename;
select 中加上distinct去除重復字段
mysqladmin drop databasename 刪除數據庫前,有提示。
顯示當前mysql版本和當前日期
select version(),current_date;
2、修改mysql中root的密碼:
shell>mysql -u root -p
mysql> update user set password=password(”xueok654123″) where user=’root’;
mysql> flush privileges //刷新數據庫
mysql>use dbname; 打開數據庫:
mysql>show databases; 顯示所有數據庫
mysql>show tables; 顯示數據庫mysql中所有的表:先use mysql;然後
mysql>describe user; 顯示表mysql數據庫中user表的列信息);
3、grant
創建一個可以從任何地方連接服務器的一個完全的超級用戶,但是必須使用一個口令something做這個
mysql> grant all privileges on *.* to [email protected]
增加新用戶
格式:grant select on 數據庫.* to [email protected] identified by “密碼”
GRANT ALL PRIVILEGES ON *.* TO [email protected] IDENTIFIED BY ’something’ WITH GRANT OPTION;
GRANT ALL PRIVILEGES ON *.* TO [email protected]%” IDENTIFIED BY ’something’ WITH GRANT OPTION;
刪除授權:
mysql> revoke all privileges on *.* from [email protected]