目录
四、授权用户tom,密码Mysql@123,能够从任何地方登录并管理数据库school。
一、MYSQL安装
1.检查自己计算机是否有gcc /gcc-c++编译器,如果没有要使用:yum install gcc gcc-c++ make -y 命令来下载基础的编译器
2.下载并安装MySQL rpm包 3.启动MySQL服务和设置开机自启动
4.启动MySQL和获得临时密码在我们第一次登陆时需要使用MySQL给的临时密码来登录
5.更改密码
二、创建数据库school,字符集为utf-8
mysql> create database school character set utf8;
三、在school数据库中创建student和score表如下图:![](https://img-blog.csdnimg.cn/8dd47971f1be418c8d0621ee882de5f6.jpeg)
1.创建student表:create table student (id int(10) not null unique auto_increment,name varchar(20) notnull,sex varchar(4),birth year,department varchar(20) not null,address varchar(50),primary key (id));![](https://img-blog.csdnimg.cn/accf0d2222ed41f589f15307941a34c3.png)
2.创建score表:mysql> create table score (id int(10) not null unique auto_increment, stu_id int(10) not null,c_name varchar(20),grade int(10),primary key (id));
四、授权用户tom,密码Mysql@123,能够从任何地方登录并管理数据库school。
1.创建tom用户:mysql> create user 'tom' @'%' identified by 'Mysql@123';
2.授权:mysql> grant all on *.* to 'tom'@'%' with grant option;
五、使用mysql客户端登录服务器,重置root密码
mysql版本 5.6 5.7 8.0
方法一:mysql版本 5.6 5.7 8.0
#mysqladmin -uroot -p'旧密码' password 新密码;
5.6版本
mysqladmin password 新密码;直接将初始化密码改为新密码
方法二:mysql版本 5.7 8.0
>alter user 'root'@localhost identified by '新密码';使用该方法用户信息全部加密
或者
>ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '新密码';
方法三:mysql 5.6 5.7
>set password for root@localhost=password('新密码');
方法四:8.0 5.6 5.7
8.0
mysql> update mysql.user set authentication_string='Mysql@123' where user='root';
5.7
update mysql.user set authentication_string=password('新密码') where user='root';
>flush privileges;
5.6
mysql> update user set password=password('新密码') where user='root' and host='localhost';
>flush privileges;