mysql常用操作

**1.初次啓動** #mysql mysql> update mysql.user set authentication_string='newpass',plugin='mysql_native_password ' where user='root'; mysql> flush privileges; mysql> exit; $ mysql -u root -p //本地登陸 $ mysql -u love -p -h ip //遠程登陸 **2.用戶操作** mysql> use mysql; mysql> create user 'love'@'localhost' identified by 'love'; //創建用戶 mysql> flush privileges; mysql> grant all on mysql.user to love@localhost; //授權 mysql> show grants for love@localhost; //查看授權 mysql> revoke all on mysql.user from love@localhost; //取消授權 mysql> update user set authentication_string='newpass' where user='love'; //修改密碼 mysql> delete from user where user='love'; //刪除用戶 mysql> drop user love@localhost; //刪除用戶 **3.查詢** mysql> show databases; //查詢數據庫(根據用戶權限) mysql> show tables; //查詢當前數據庫有哪些表 mysql> show columns from user; //查詢user表所有列的列名和屬性 mysql> select count(*) from user; //查詢有多少條記錄 4.DDL數據定義 mysql> create database abc; //創建數據庫abc mysql> create table user_info( //創建user_info表 >> id int primary key, //id列int類型, 主鍵 >> name varchar(255) unique, // name列字符串類型,唯一約束 >> family text not null); //family列text類型,非空 mysql> alter table user_info rename to info; //改表名 mysql> alter table info add phone int; //增加列 mysql> alter table info change column phone pho int; //改列名 mysql> alter table info drop column phone; //刪除列 5.DML數據操作 mysql> insert into t1 mysql> delete from t1 mysql> update t1 set mysql> select id from t1
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章