实验要求:
1.使用源码安装MySQL8.0.x
2.创建数据库school,字符集为utf8
3.在school数据库中创建student和score表
4.授权用户tom,密码Mysql@123,能够从任何地方登录并管理数据库school。
5.使用mysql客户端登陆服务器,重置root密码
实验操作:
1.下载可从mysql官网(www.mysql.com)中选择你所需要的版本,然后你可通过一下命令进行安装。
wget +网址#下载所需要的mysql
sudo yum install -y gcc gcc-c++ make zlib-devel # 安装编译所需依赖
tar -xzf mysql-8.0.x.tar.gz # 解压源码包
cd mysql-8.0.x
./configure
make
sudo make install # 编译并安装MySQL
2.创建数据库school,字符集为UTF-8
mysql> create database school character set utf8;
Query OK, 1 row affected, 1 warning (0.00 sec)
3.在school数据库中创建student和score表
mysql> use school;
Database changed
mysql> create table student(
-> id int(10) not null unique primary key,
-> name varchar(20) not null,
-> sex varchar(4),
-> bitrh year,
-> department varchar(20),
-> address varchar(20)
-> );
Query OK, 0 rows affected, 1 warning (0.01 sec)
mysql> create table score(
-> id int(10) not null unique primary key auto_increment,
-> stu_id int(10) not null,
-> c_name varchar(20),
-> grade int(10)
-> );
Query OK, 0 rows affected, 3 warnings (0.00 sec)
mysql> desc student;
+------------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+------------+-------------+------+-----+---------+-------+
| id | int | NO | PRI | NULL | |
| name | varchar(20) | NO | | NULL | |
| sex | varchar(4) | YES | | NULL | |
| bitrh | year | YES | | NULL | |
| department | varchar(20) | YES | | NULL | |
| address | varchar(20) | YES | | NULL | |
+------------+-------------+------+-----+---------+-------+
6 rows in set (0.00 sec)
mysql> desc score;
+--------+-------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+--------+-------------+------+-----+---------+----------------+
| id | int | NO | PRI | NULL | auto_increment |
| stu_id | int | NO | | NULL | |
| c_name | varchar(20) | YES | | NULL | |
| grade | int | YES | | NULL | |
+--------+-------------+------+-----+---------+----------------+
4 rows in set (0.00 sec)
4.授权用户tom,密码Mysql@123,能够从任何地方登录并管理数据库school
mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> create user 'tom'@'%' identified by 'Mysql@123';
Query OK, 0 rows affected (0.01 sec)
mysql> grant all privileges on school.*to 'tom'@'%';
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> exit
Bye
[root@rhcsa1 ~]# mysql -utom -pMysql@123
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 12
Server version: 8.0.34 MySQL Community Server - GPL
Copyright (c) 2000, 2023, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> use school;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
5.使用mysql客户端登陆服务器,重置root密码
[root@rhcsa1 ~]# grep 'password' /var/log/mysqld.log
2023-10-13T03:47:22.390831Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: 3aL(li;pA<tr
[root@rhcsa1 ~]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 10
Server version: 8.0.34
Copyright (c) 2000, 2023, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
mysql> alter user 'root'@'localhost' identified by 'Mysql@123';
Query OK, 0 rows affected (0.00 sec)
mysql> exit
Bye
[root@rhcsa1 ~]# mysql -uroot -pMysql@123
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 11
Server version: 8.0.34 MySQL Community Server - GPL
Copyright (c) 2000, 2023, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>