千家信息网

mysql专业语句详解

发表于:2026-11-01 作者:千家信息网编辑
千家信息网最后更新 2026年11月01日,下文内容主要给大家带来mysql专业语句详解,所讲到的知识,与书籍略有不同,都是专业技术人员在与用户接触过程中,总结出来的,具有一定的经验分享价值,希望给广大读者带来帮助。一、字符集1.列出可用字符集
千家信息网最后更新 2026年11月01日mysql专业语句详解

下文内容主要给大家带来mysql专业语句详解,所讲到的知识,与书籍略有不同,都是专业技术人员在与用户接触过程中,总结出来的,具有一定的经验分享价值,希望给广大读者带来帮助。


一、字符集


1.列出可用字符集

show character set;


2.列出一个字符集的校对规则

show collation like 'latin1%'


3.数据库字符集和校对规则

create database li default character set latin1 collate latin1_swedish_ci;


4.云服务器字符集和校对规则

(1)编译时指定参数设置

./configure --with-charset=latin1 --with-collation=latin1_german1_ci


(2)启动mysql时初始选项设置

mysqld --default-character-set=latin1 --default-collation=latin1_swedish_ci


5.表字符集和校对规则

create table test1 (id int,name char(20)) default character set latin1 collate latin1_danish_ci;

6.列字符集和校对规则

create table test2 (coll1 varchar(5) character set latin1 collate latin1_german1_ci);


7显示全部可用的字符集

show character set like 'latin1%';


8.显示创建数据库语句

show create database li;


9.显示用户的连接数

show processlist(默认列出100条)

show full processlist(列出全部的)


二、sql语句详解


1.alter语句

(1)更改列名

alter table test change id number integer; 将一个int类型列的id重命名为number


(2)更改列类型

alter table test change number a bigint;


2.drop语句

(1)drop数据库

drop database li;


(2)drop索引

drop index test3;


(3)drop表

drop table test;

3.rename语句

(1)rename 表

rename table test1 to test;


4.delete语句

delete from test;


5.insert语句

insert into test (id,name) values (1,'lisi')


6.load data file语句

LOAD DATA INFILE 'data.txt' INTO TABLE db2.my_table;

三、用户管理

1.创建用户

create user wang@localhost identified by '123456';

2.删除用户

drop user wang@localhost;


3.创建授权用户

grant create,delete on test.* to wang@'192.168.10.%' identified by '123456'


4.查看用户

select user,host from mysql.user;


5.刷新授权表

flush privileges;


6.查看用户权限

show grants for wang;


7.更改密码

如果是初始登陆的话,是空密码,需要设置

mysqladmin -uroot -password '123456'

如果已知原密码再改密码

mysqladmin -uroot -p123456 password '1234567'

如果是已经改了但是又忘了,并且已经退出了Mysql的登录,则需要跳过授权表启动mysql

首先停掉正在运行的mysql

然后mysqld_safe --skip-grant-tables &

mysql -uroot

update mysql.user set password=password('123456') where user='root';

flush privileges;

查看用户

select user();


四、mysql监控

1.查看某个数据库的磁盘使用空间

select concat(truncate(sum(data_length)/1024/1024,2),'MB') as data_size,
concat(truncate(sum(max_data_length)/1024/1024,2),'MB') as max_data_size,
concat(truncate(sum(data_free)/1024/1024,2),'MB') as data_free,
concat(truncate(sum(index_length)/1024/1024,2),'MB') as index_size

from information_schema.tables where TABLE_SCHEMA = 'databasename';


2.查看所有的数据库的磁盘空间

select TABLE_SCHEMA,concat(truncate(sum(data_length)/1024/1024,2),'MB') as data_size, concat(truncate(sum(max_data_length)/1024/1024,2),'MB') as max_data_size,

concat(truncate(sum(data_free)/1024/1024,2),'MB') as data_free,

concat(truncate(sum(index_length)/1024/1024,2),'MB') as index_size

from information_schema.tables group by TABLE_SCHEMA;


3.查询某张表的空间

select concat(truncate(sum(data_length)/1024/1024,2),'MB') as data_size,

concat(truncate(sum(max_data_length)/1024/1024,2),'MB') as max_data_size,

concat(truncate(sum(data_free)/1024/1024,2),'MB') as data_free,

concat(truncate(sum(index_length)/1024/1024,2),'MB') as index_size

from information_schema.tables

where TABLE_NAME = 'tablename';


对于以上关于mysql专业语句详解,如果大家还有更多需要了解的可以持续关注我们的行业推新,如需获取专业解答,可在官网联系售前售后的,希望该文章可给大家带来一定的知识更新。

语句 用户 字符 字符集 数据 数据库 校对 规则 专业 密码 空间 知识 磁盘 类型 不同 下文 书籍 人员 价值 内容 数据库的安全要保护哪些东西 数据库安全各自的含义是什么 生产安全数据库录入 数据库的安全性及管理 数据库安全策略包含哪些 海淀数据库安全审计系统 建立农村房屋安全信息数据库 易用的数据库客户端支持安全管理 连接数据库失败ssl安全错误 数据库的锁怎样保障安全 互联网高科技 南京欣网互联网络科技有限公司 云信互联网科技有限公司 金融科技还是互联网 互联网巨头反垄断金融科技 朗新科技与工业互联网 互联网未来科技 北京互联网络科技有限公司 多迪互联网科技有限公司 济南华为互联网科技产业总部基地 互联网经济与金融科技 互联网公司科技股 上海宁丞科技互联网 乌鲁木齐新华智原互联网科技学校 翼展科技 首家互联网医院 抖集互联网科技技术咨询 吉林省码上互联网科技电话 科技互联网公司两年变化 10位科技互联网大佬 互联网 科技节活动 微视频大赛 手冲咖啡和咖啡机区别 互联网科技公司起名 互联网科技会 科技制造互联网公司 北京互联网科技有限公司 广州互联网络科技有限公司 南山科技园互联网公司有哪些 阿大互联网科技有限公司 互联网公司高科技产品 银川新华互联网科技学校是国营吗
0