//查看数据库 show databases //使用默认字符集和排序规则创建数据库 create database db_name; //创建数据库并指定字符集编码 create database if not exists db_name default character set = 'utf8'; //创建数据库并指定字符集编码和排序规则 create database db_name DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci; //删除数据库 drop database db_name //指定当前数据库 USE db1;
//插入数据 insert into Student values ('20180001','小明','男',20,'一班'); //按字段插入数据 insert into Student (Sno,Sname,Ssex,Sage,Sclass) values ('20180003','小红','男',18,'二班'); //删除记录 delete from Student where Sno='20180001' //删除所有 delete * from Student //更新 update Student set Sclass = '一班' where Sname='小红' //查询 select * from Student;
//指定数据库 Use mysql; //查询所有用户 Select user,host from user; //创建本地访问用户 create user admin@'localhost' identified by '密码'; //创建允许远程访问用户 create user admin@'%' identified by '密码'; //授权所有权限 GRANT ALL PRIVILEGES ON *.* TO admin@"localhost"; //授权所有权限 GRANT ALL PRIVILEGES ON *.* TO admin@"%"; //修改密码 mysql 5.7-8.0 ALTER USER 'admin'@'localhost' IDENTIFIED BY '密码'; //修改密码 mysql 5.6 update user set password=password("你的新密码") where user="admin"; //修改密码 mysql 5.5 use mysql; set password for admin@localhost = password('密码'); //刷新权限 flush privileges; //删除用户 drop user admin@'%';
七、查看mysql常用参数
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
//查询mysql版本 select @@version; select version(); //查询进程列表 show processlist; //查看进程列表完整信息 show full processlist; //查看线程数 show status like 'Threads%'; //查看连接数 show variables like '%max_connections%'; //查看数据默认字符集 show variables like '%character%'; //查看数据库默认排序规则 show variables like 'collation%'; //查看支持字符集 show charset;