mysql建表常用sql语句个人经验分享
时间:2024-01-27 12:30:48
连接:mysql -h主机地址 -u用户名 -p用户密码 (注:u与root可以不用加空格,其它也一样)
断开:exit (回车)
创建授权:grant select on 数据库.* to 用户名@登录主机 identified by \"密码\"
修改密码:mysqladmin -u用户名 -p旧密码 password 新密码
删除授权: revoke select,insert,update,delete om *.* from test2@localhost;
显示数据库:show databases;
显示数据表:show tables;
显示表结构:describe 表名;
创建库:create database 库名;
删除库:drop database 库名;
使用库(选中库):use 库名;
创建表:create table 表名 (字段设定列表);
删除表:drop table 表名;
修改表:alter table t1 rename t2
查询表:select * from 表名;
清空表:delete from 表名;
备份表: mysqlbinmysqldump -h(ip) -uroot -p(password) databasename tablename > tablename.sql
恢复表: mysqlbinmysql -h(ip) -uroot -p(password) databasename tablename < tablename.sql(操作前先把原来表删除)
增加列:ALTER TABLE t2 ADD c INT UNSIGNED NOT NULL AUTO_INCREMENT,ADD INDEX (c);
修改列:ALTER TABLE t2 MODIFY a TINYINT NOT NULL, CHANGE b c CHAR(20);
删除列:ALTER TABLE t2 DROP COLUMN c;
备份数据库:mysql\bin\mysqldump -h(ip) -uroot -p(password) databasename > database.sql
恢复数据库:mysql\bin\mysql -h(ip) -uroot -p(password) databasename < database.sql
复制数据库:mysql\bin\mysqldump --all-databases > all-databases.sql
修复数据库:mysqlcheck -A -o -uroot -p54safer
文本数据导入: load data local infile \"文件名\" into table 表名;
数据导入导出:mysql\bin\mysqlimport database tables.txt
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
使用php get_headers 判断URL是否有效的解决办法
Mysql数据库常用命令
MySQL数据库配置优化的方案
详解使用PyInstaller将Pygame库编写的小游戏程序打包为exe文件
![](https://img.aspxhome.com/file/2023/2/109992_0s.png)
pycharm中选中一个单词替换所有重复单词的实现方法
![](https://img.aspxhome.com/file/2023/7/121767_0s.png)
PyQt5中QSpinBox计数器的实现
![](https://img.aspxhome.com/file/2023/5/105865_0s.jpg)
Python使用sqlite3第三方库读写SQLite数据库的方法步骤
![](https://img.aspxhome.com/file/2023/2/86232_0s.png)
Python远程开发环境部署与调试过程图解
![](https://img.aspxhome.com/file/2023/9/72199_0s.png)
使用Python在Windows下获取USB PID&VID的方法
Web开发的改良
SQL Server实现group_concat功能的详细实例
![](https://img.aspxhome.com/file/2023/5/119265_0s.png)
python 列表输出重复值以及对应的角标方法
MySQL高可用架构之MHA架构全解
![](https://img.aspxhome.com/file/2023/4/111364_0s.png)
Python 之 Json序列化嵌套类方式
![](https://img.aspxhome.com/file/2023/9/107119_0s.jpg)
几种设置表单元素中文本输入框不可编辑的方法总结
asp分段插入数据库
javascript数组的使用
Golang中slice删除元素的性能对比
Python变量、数据类型、数据类型转换相关函数用法实例详解
![](https://img.aspxhome.com/file/2023/3/65443_0s.png)
Python中号称神仙的六个内置函数详解
![](https://img.aspxhome.com/file/2023/3/70703_0s.jpg)