Exercícios básicos de fortalecimento da operação do banco de dados MySQL
Prefácio
Este ambiente é baseado no sistema Centos 7.8 para construir o MySQL-5.7.14 para
construção específica, consulte a construção do ambiente MySQL-5.7.14
1、使用源码安装MySQL 5.7。
https://blog.csdn.net/XY0918ZWQ/article/details/109186371
2、创建数据库school,字符集为utf8
mysql> create database school;
mysql> use school;
3、在school数据库中创建Student和Score表
Score:
mysql> create table Score
-> (Id int(10) primary key auto_increment comment '编号',
-> Stu_id int(10) not null comment '学号',
-> C_name varchar(20) comment '课程名',
-> Grade int(10) comment '分数');
Student:
mysql> create table Student
-> (Id int(10) primary key auto_increment comment '学号',
-> Name varchar(20) not null comment '姓名',
-> Gender varchar(4) comment '性别',
-> Birth year comment '出生年月',
-> Department varchar(20) not null comment '院系',
-> Address varchar(50) comment '家庭住址');
4、授权用户tom,密码mysql,能够从任何地方登录并管理数据库school。
方法一:
mysql> create user tom1@'%';
mysql> grant all on school.* to tom1@'%' identified by 'mysql';
方法二:
mysql> grant all on *.* to 'tom2'@'%' identified by 'mysql';
5、使用mysql客户端登录服务器,重置root密码
(1) 停止mysqld服务
[root@mysql-rpm ~]# systemctl stop mysqld
(2) 修改配置文件--跳过权限表
[root@mysql-rpm ~]# vim /etc/my.cnf
skip-grant-tables
(3) 启动mysqld服务
[root@mysql-rpm ~]# systemctl start mysqld
(4) 空密码登,重置密码
mysql> update mysql.user
-> set authentication_string=password('12345678')
-> where user='root' and host='localhost';
Query OK, 1 row affected, 1 warning (0.00 sec
(5) 删除跳过权限表命令,重启服务
[root@mysql-rpm ~]# systemctl start mysqld
(6) 登录验证