命令行操作mysql
生活随笔
收集整理的這篇文章主要介紹了
命令行操作mysql
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
1、通過命令行連接mysql:
1、輸入命令:mysql -h localhost(服務(wù)IP地址) -u root(用戶名) -P 3306(服務(wù)端口)-p
2、輸入密碼
2、顯示數(shù)據(jù)庫、表:
show databases; //顯示存在的數(shù)據(jù)庫 use test; //test為相對(duì)應(yīng)的數(shù)據(jù)庫名稱,表示使用某個(gè)數(shù)據(jù)庫 show tables; //顯示此數(shù)據(jù)庫的所有表3、命令行查詢表結(jié)構(gòu)
1、desc tabl_name;(查詢表結(jié)構(gòu)信息) 2、select * from information_schema.columns where table_schema = 'db' #表所在數(shù)據(jù)庫 and table_name = 'tablename' ; #你要查的表(查詢表結(jié)構(gòu)信息) 3、select column_name, column_comment from information_schema.columns where table_schema ='db' and table_name = 'tablename' ;(只查詢列名、注釋信息) 4、select table_name,table_comment from information_schema.tables where table_schema = 'db' and table_name ='tablename'(查看表的注釋)4、執(zhí)行增刪改查:
create database test; //建數(shù)據(jù)庫。名字為test create table user(id int(4) not null primary key auto_increment,username char(20)not null,password char(20) not null);//創(chuàng)建數(shù)據(jù)庫,名為userinsert into user (1,'duoduo','921012'); //插入一條數(shù)據(jù)select * from user; //查詢所有的信息5、用戶授權(quán):
grant select on *.* to 'reader'@'%' identified by '123456' WITH GRANT OPTION flush privileges總結(jié)
以上是生活随笔為你收集整理的命令行操作mysql的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 如何解决电脑关机速度慢怎么办 电脑关机速
- 下一篇: mysql 1030 error:Got