欢迎访问 生活随笔!

生活随笔

当前位置: 首页 >

命令行操作mysql

发布时间:2023/12/4 78 豆豆
生活随笔 收集整理的这篇文章主要介绍了 命令行操作mysql 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

1、通过命令行连接mysql:
1、输入命令:mysql -h localhost(服务IP地址) -u root(用户名) -P 3306(服务端口)-p
2、输入密码

2、显示数据库、表:

show databases; //显示存在的数据库 use test; //test为相对应的数据库名称,表示使用某个数据库 show tables; //显示此数据库的所有表

3、命令行查询表结构

1desc tabl_name;(查询表结构信息) 2select * from information_schema.columns where table_schema = 'db' #表所在数据库 and table_name = 'tablename' ; #你要查的表(查询表结构信息) 3select column_name, column_comment from information_schema.columns where table_schema ='db' and table_name = 'tablename' ;(只查询列名、注释信息) 4select table_name,table_comment from information_schema.tables where table_schema = 'db' and table_name ='tablename'(查看表的注释)

4、执行增删改查:

create database test; //建数据库。名字为test create table user(id int(4) not null primary key auto_increment,username char(20)not null,password char(20) not null);//创建数据库,名为userinsert into user (1,'duoduo','921012'); //插入一条数据select * from user; //查询所有的信息

5、用户授权:

grant select on *.* to 'reader'@'%' identified by '123456' WITH GRANT OPTION flush privileges

总结

以上是生活随笔为你收集整理的命令行操作mysql的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。