游戏服务器使用MySQL常用命令
游戏服务器使用MySQL常用命令
启动MySQL服务:service mysqld start 或 systemctl start mysqld.service
停止MySQL服务:service mysqld stop 或 systemctl stopt mysqld.service
游戏服务器重启MySQL服务:service mysqld restart 或 systemctl restart mysqld.service
查看MySQL服务状态:service mysqld status 或 systemctl status mysqld.service
游戏服务器连接MySQL:mysql –uroot –p
游戏服务器退出mysql服务:exit
查看用户数据库权限:show grants;
查看数据库:show databases;
重命名数据库:rename database 原数据库名 to 新数据库名
删除数据库:drop database 数据库名;
使用数据库:use 数据库名;
查看数据库包含的表:show tables;
重命名表:alter table 原表名 rename to 新表名; 还可使用:rename table 数据库.原表名 to 数据库.新表名; (可用于表在数据库的迁移)
创建表:create table if not exists 表名(表头1 数据类型(数据长度) primary key,表头2,数据类型(数据长度))engine=innodb default charset=utf8;
复制表:create table 新表名 as ( select * from 表 [where 条件] );
只复制表结构:create table 新表名 as ( select * from 表 where null);
查看表结构:desc 表名;
新增字段:alter table 表名 add 表头 数据类型(数据长度);
删除字段:alter table 表名 drop 表头 ;
修改字段:alter table 表名 modify 原表头 新表头 数据类型(数据长度);
添加外键:alter table 表名 add constraint 索引名(一般以fk_开头) foreign key(外键名) references 关联外键的表名(关联的主键字段);
插入数据:insert into 表名 ( 列名1,列名2,...,列名n ) values ( 值a1,值a2,...,值an ), ( 值b1,值b2,...,值bn ),…;
删除数据:delete from 表名 [where 子句];
快速删除数据:truncat 表1;删除表1后创建一个新的表,结构名称与表1相同;
修改数据:update 表名 set 列名1=新值1, 列名2=新值2 [where子句];
查询数据:select 列名1,列名2 from 表名 [where子句];
引入sql脚本:source 文件路径/文件.sql【艾娜】