21次8.5(mysql用户创建与授权、角色创建)

1.环境准备

rm -rf /etc/my.cnf    //清空/etc目录下的my.cnf
yum -y remove mariadb   //移除mariadb
find / -name "*mysql*" -exec rm -rf {} \;    //删除mysql所有遗留文件

2.安装mysql绿包

[root@mysql01 ~]# ls
anaconda-ks.cfg  mysql-8.0.33-linux-glibc2.12-x86_64.tar
[root@mysql01 ~]# tar -xvf mysql-8.0.33-linux-glibc2.12-x86_64.tar 
[root@mysql01 ~]# ls
anaconda-ks.cfg                             mysql-router-8.0.33-linux-glibc2.12-x86_64.tar.xz
mysql-8.0.33-linux-glibc2.12-x86_64.tar     mysql-test-8.0.33-linux-glibc2.12-x86_64.tar.xz
mysql-8.0.33-linux-glibc2.12-x86_64.tar.xz
[root@mysql01 ~]# tar -xf mysql-8.0.33-linux-glibc2.12-x86_64.tar.xz 
[root@mysql01 ~]# ls
anaconda-ks.cfg                          mysql-8.0.33-linux-glibc2.12-x86_64.tar.xz
mysql-8.0.33-linux-glibc2.12-x86_64      mysql-router-8.0.33-linux-glibc2.12-x86_64.tar.xz
mysql-8.0.33-linux-glibc2.12-x86_64.tar  mysql-test-8.0.33-linux-glibc2.12-x86_64.tar.xz
[root@mysql01 ~]# cd mysql-8.0.33-linux-glibc2.12-x86_64/
​

3.配置mysql工作环境

[root@mysql01 ~]# cp -r mysql-8.0.33-linux-glibc2.12-x86_64/ /usr/local/mysql/   #将项目文件移动到/usr/local/mysql/
[root@mysql01 ~]# useradd -r -s /sbin/nologin mysql   #没有再创建
[root@mysql01 ~]# id mysql
uid=997(mysql) gid=995(mysql) 组=995(mysql)
[root@mysql01 ~]# mkdir /usr/local/mysql/mysql-files   #创建目录

修改mysql-files单位权限为750,所属的组和属主都是mysqsl

[root@mysql01 ~]# chown mysql:mysql /usr/local/mysql/mysql-files/
[root@mysql01 ~]# chmod 750 /usr/local/mysql/mysql-files/
[root@mysql01 ~]# ll /usr/local/mysql/
drwxr-x---.  2 mysql mysql      6 8月   5 09:54 mysql-files

初始化数据库,找到初始化密码

/usr/local/mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql/
2024-08-05T02:41:40.590343Z 0 [System] [MY-013169] [Server] /usr/local/mysql/bin/mysqld (mysqld 8.0.33) initializing of server in progress as process 2218
2024-08-05T02:41:40.597799Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2024-08-05T02:41:41.306286Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2024-08-05T02:41:42.257638Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: iPtaRfFt>8AO
[root@mysql001 ~]# cd /usr/local/mysql/
[root@mysql001 mysql]# ls
bin  data  docs  include  lib  LICENSE  man  mysql-files  README  share  support-files
[root@mysql001 mysql]# chown -R mysql:mysql /usr/local/mysql/data
[root@mysql001 mysql]# chmod -R 755 /usr/local/mysql/data
[root@mysql001 mysql]# service mysql8 start
Starting MySQL.Logging to '/usr/local/mysql/data/mysql001.err'.
. SUCCESS! 
[root@mysql001 ~]# cd /usr/local/mysql/
[root@mysql001 mysql]# ls    #查看是否生成了data目录
bin  data  docs  include  lib  LICENSE  man  mysql-files  README  share  support-files
[root@mysql ~]# /usr/local/mysql/bin/mysql_ssl_rsa_setup --datadir=/usr/local/mysql/data    //创建安全加密连接
 [root@mysql ~]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql8    //将mysql.server文件放到/etc/init.d/目录下,方便启动mysql服务 service mysql start
 [root@mysql ~]# service mysql8 start    //启动mysql服务
 Starting MySQL.Logging to '/usr/local/mysql/data/mysql.err'.
 ....... SUCCESS!
 [root@mysql ~]# systemctl stop firewalld   
 [root@mysql ~]# systemctl disable firewalld
 Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
 Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
 [root@mysql ~]# /usr/local/mysql/bin/mysql -uroot -p    //进入mysql中
 Enter password: 
 Welcome to the MySQL monitor.  Commands end with ; or \g.
 Your MySQL connection id is 9
 Server version: 8.0.33
 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 -hip地址 -p3306 -uroot -p(远程连接使用)

4.mysql基础命令

1.修改密码
 mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'Root@123456';   
2.授权远程登录
mysql> create user 'root'@'%' identified with mysql_native_password by 'Root@123456';    //创建root远程登录
3.查看表结构
 mysql&
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值