安装glibc
glibc mysql 俗称绿色mysql
安装之前删掉mariadb:
数据库初始化时候,会⾃动找my.cnf配置,但是原有的mariadb配
置⽂件,会失败
root@mysql3 \~\]# ls -l /etc/my.cnf -rw-r--r--. 1 root root 570 6月 8 2017 /etc/my.cnf \[root@mysql3 \~\]# rm -rf /etc/my.cnf \[root@mysql3 \~\]# yum -y remove mariadb 步骤: 1.解压 \[root@mysql3 \~\]# tar -xvf mysql-8.0.33-linux-glibc2.12-x86_64.tar \[root@mysql3 \~\]# ls mysql-8.0.33-linux-glibc2.12-x86_64.tar mysql-8.0.33-linux-glibc2.12-x86_64.tar.xz mysql-router-8.0.33-linux-glibc2.12-x86_64.tar.xz mysql-test-8.0.33-linux-glibc2.12-x86_64.tar.xz \[root@mysql3 \~\]# tar -xf mysql-8.0.33-linux-glibc2.12-x86_64.tar.xz \[root@mysql3 \~\]# cd mysql-8.0.33-linux-glibc2.12-x86_64/ \[root@mysql3 mysql-8.0.33-linux-glibc2.12-x86_64\]# ls bin docs include lib LICENSE man README share support-files 2.改名: \[root@mysql3 \~\]# cp -r mysql-8.0.33-linux-glibc2.12-x86_64 /usr/local/mysql/ 3.查看依赖库,没有的话安装 \[root@mysql3 \~\]# yum list installed \| grep libaio libaio.x86_64 0.3.109-13.el7 @anaconda \[root@mysql3 \~\]# echo $? 0 4.创建用户 \[root@mysql3 \~\]# id mysql id: mysql: no such user \[root@mysql3 \~\]# useradd -r -s /sbin/nologin mysql \[root@mysql3 \~\]# id mysql uid=997(mysql) gid=995(mysql) 组=995(mysql) 5.创建一个mysql-files,修改mysql-files文件权限750和所属mysql \[root@mysql3 \~\]# mkdir /usr/local/mysql/mysql-files \[root@mysql3 \~\]# chown mysql:mysql /usr/local/mysql/mysql-files/ \[root@mysql3 \~\]# chmod 750 /usr/local/mysql/mysql-files/ 6.初始化数据库,找到初始密码 \[root@mysql3 \~\]# /usr/local/mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql 7.查看是否初始化成功,可以看文件夹中是否有data文件夹 \[root@mysql3 \~\]# ls /usr/local/mysql/ bin docs lib man README support-files data include LICENSE mysql-files share 8.设置ssl安全加密连接 敏感数据 \[root@mysql3 \~\]# /usr/local/mysql/bin/mysql_ssl_rsa_setup --datadir=/usr/local/mysql/data 9.其他配置 \[root@mysql3 \~\]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql8 默认情况下,启动文件默认安装目录在/usr/local/目录下 10.启动服务,不能使用systemctl \[root@mysql3 \~\]# service mysql8 start 编写脚本:自动化安装mysql \[root@mysql1 \~\]# vim mysql.sh  1.远程登录的前提条件:mysql.user表中的host属性为%,如果是localhost就是不允许远程登录,update mysql.user set host="%" where user="root",flush privileges; 2.远程管理,可以使用图形化工具,sqlyog,navicat,命令工具就是客户端工具 mysql 3.mysql -h主机IP或域名 -P端口 -u用户名 -p密码 -h :如果是localhost或者是127.0.0.1可省略 -P :默认是3306,如果是默认的,可以省略 -p : 可以不换行直接输入,也可以换行,不回显输入密码 ## mysql的权限 ##### 用户 创建用户: mysql\> create user 'wangjia'@'%' identified by 'wangjia'; Query OK, 0 rows affected (0.02 sec) mysql\> select host,user from mysql.user; +-----------+------------------+ \| host \| user \| +-----------+------------------+ \| % \| wangjia \| \| localhost \| mysql.infoschema \| \| localhost \| mysql.session \| \| localhost \| mysql.sys \| \| localhost \| root \| +-----------+------------------+ 5 rows in set (0.00 sec) 给权限: mysql\> grant all on \*.\* to 'wangjia'; Query OK, 0 rows affected (0.00 sec) all代表所有的权限,第一个\*表示所有的库,第二个\*表示所有的表 创建库: create database if not exists test; 添加lilaosi账号,修改密码: create user 'lilaosi'@'%' identified by 'lilaosi_123'; alter user 'lilaosi' identified by 'lilaosi'; 使用root账号,为lilaosi账号添加test库中所有的表的所有权限: grant all on test.\* to 'lilaosi'; # lilaosi就获得了test库中所有的表的操作权限,但是,由于 root没有给lilaosimysql库的权限,所以lilaosi账号⽆法查看 mysql库 mysql\> show databases; +--------------------+ \| Database \| +--------------------+ \| information_schema \| \| performance_schema \| \| test \| +--------------------+ 3 rows in set (0.01 sec) 删除用户: drop user 'wangjia'; 将test库中user表的查看权限给abc:(在root账号下) mysql\> grant select on test.user to 'abc'; Query OK, 0 rows affected (0.01 sec) 在abc账号下: mysql\> insert into user values(7,'erha','erha'); ERROR 1142 (42000): INSERT command denied to user 'abc'@'localhost' for table 'user' 为abc添加insert权限:(在root权限下) mysql\> grant insert on test.user to 'abc'; Query OK, 0 rows affected (0.00 sec) 在abc账号下: mysql\> insert into test.user values(5,'wangmizi','wangmizi'); Query OK, 1 row affected (0.01 sec) 查看abc的权限: mysql\> show grants for 'abc'; +----------------------------------------------------+ \| Grants for abc@% \| +----------------------------------------------------+ \| GRANT USAGE ON \*.\* TO \`abc\`@\`%\` \| \| GRANT SELECT, INSERT ON \`test\`.\`user\` TO \`abc\`@\`%\` \| +----------------------------------------------------+ 2 rows in set (0.00 sec) #### 角色 一次一次添加权限不方便,因此引出了角色: 添加角色:jingli , yuangongjuese mysql\> create role 'jingli'; Query OK, 0 rows affected (0.00 sec) mysql\> create role 'yuangongjuese'; Query OK, 0 rows affected (0.01 sec) 给角色给权限:jingli (插入,更新,删除,选择),yuangongjuese(插入,选择) mysql\> grant insert,update,delete,select on test.user to 'jingli'; Query OK, 0 rows affected (0.00 sec) mysql\> grant insert,select on test.user to 'yuangongjuese'; Query OK, 0 rows affected (0.00 sec) 查看角色保存的表格: mysql\> select host,user from mysql.user; 查看角色的权限: mysql\> show grants for 'jingli'; mysql\> show grants for 'yuangongjuese'; 创建用户bbb有插入,更新,删除,选择权限(增删改查),ccc有插入和选择权限: 创建用户,分别加入对应的角色里面即可: mysql\> create user 'bbb'@'%' identified by 'bbb'; Query OK, 0 rows affected (0.00 sec) mysql\> create user 'ccc'@'%' identified by 'ccc'; Query OK, 0 rows affected (0.00 sec) mysql\> grant jingli to 'bbb'; Query OK, 0 rows affected (0.00 sec) mysql\> show grants for bbb; +---------------------------------+ \| Grants for bbb@% \| +---------------------------------+ \| GRANT USAGE ON \*.\* TO \`bbb\`@\`%\` \| \| GRANT \`jingli\`@\`%\` TO \`bbb\`@\`%\` \| +---------------------------------+ 2 rows in set (0.00 sec) mysql\> grant yuangongjuese to 'ccc'; Query OK, 0 rows affected (0.00 sec) mysql\> show grants for ccc; +----------------------------------------+ \| Grants for ccc@% \| +----------------------------------------+ \| GRANT USAGE ON \*.\* TO \`ccc\`@\`%\` \| \| GRANT \`yuangongjuese\`@\`%\` TO \`ccc\`@\`%\` \| +----------------------------------------+ 2 rows in set (0.00 sec) 刷新权限: mysql\> flush privileges;