Centos7 安装mysql8

1、将mysql安装包上传

mysql-8.0.21-el7-x86_64.tar

2、解压

tar -xvf mysql-8.0.21-el7-x86_64.tar

解压后有3个文件

[root@cdh03 software]# tar -xvf mysql-8.0.21-el7-x86_64.tar 
mysql-test-8.0.21-el7-x86_64.tar.gz
mysql-8.0.21-el7-x86_64.tar.gz
mysql-router-8.0.21-el7-x86_64.tar.gz

3、解压 mysql-8.0.21-el7-x86_64.tar.gz

tar -xzvf mysql-8.0.21-el7-x86_64.tar.gz

4、改名

mv -f mysql-8.0.21-el7-x86_64 mysql80

5、创建MySQL 组

1)创建mysql 组
groupadd mysql

2)创建MySQL用户但该用户不能登陆(-s /bin/false参数指定mysql用户仅拥有所有权,而没有登录权限)
useradd -r -g mysql -s /bin/false mysql

3)把刚创建的mysql用户加入到mysql组下
chown -R mysql:mysql ./
[root@cdh03 software]# groupadd mysql
[root@cdh03 software]# useradd -r -g mysql -s /bin/false mysql
[root@cdh03 software]# chown -R mysql:mysql ./

6、创建mysql 安装初始化配置文件

vi /etc/my.cnf

添加下面这段命令后保存并退出

[mysqld]
# 设置3306端口
port=3306
# 设置mysql的安装目录
basedir=/software/mysql80
# 设置mysql数据库的数据的存放目录
datadir=/software/mysql80/mysqldb
# 允许最大连接数
max_connections=10000
# 允许连接失败的次数。这是为了防止有人从该主机试图攻击数据库系统
max_connect_errors=10
# 服务端使用的字符集默认为UTF8
character-set-server=utf8
# 创建新表时将使用的默认存储引擎
default-storage-engine=INNODB
# 默认使用“mysql_native_password”插件认证
default_authentication_plugin=mysql_native_password
#设置不区分大小写
lower_case_table_names=1
[mysql]
# 设置mysql客户端默认字符集
default-character-set=utf8
[client]
# 设置mysql客户端连接服务端时默认使用的端口
port=3306
default-character-set=utf8

 

7、安装mysql

进入mysql 安装目录下
cd /software/mysql80/bin
安装MySQL,并记住随机命令
 ./mysqld --initialize --console

[root@cdh03 bin]# ./mysqld --initialize --console
2020-08-07T15:54:30.382640Z 0 [System] [MY-013169] [Server] /software/mysql80/bin/mysqld (mysqld 8.0.21) initializing of server in progress as process 2160
2020-08-07T15:54:30.387180Z 0 [Warning] [MY-013242] [Server] --character-set-server: 'utf8' is currently an alias for the character set UTF8MB3, but will be an alias for UTF8MB4 in a future release. Please consider using UTF8MB4 in order to be unambiguous.
2020-08-07T15:54:30.438042Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2020-08-07T15:54:31.596423Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2020-08-07T15:54:34.300843Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: E3S9al(EFkuy

8、启动MySQL服务

[root@cdh03 mysql80]# cd support-files/
[root@cdh03 support-files]# pwd
/software/mysql80/support-files
[root@cdh03 support-files]# ./mysql.server start
Starting MySQL.Logging to '/software/mysql80/mysqldb/cdh03.err'.
. ERROR! The server quit without updating PID file (/software/mysql80/mysqldb/cdh03.pid).

在mysql安装目录下重新授权后,再次自行启动MySQL命令
[root@cdh03 support-files]# ./mysql.server start
Starting MySQL.Logging to '/software/mysql80/mysqldb/cdh03.err'.
.. SUCCESS! 
[root@cdh03 support-files]# 

9、mysql加入系统进程中

[root@cdh03 support-files]# cp mysql.server /etc/init.d/mysqld

重启MySQL服务

[root@cdh03 support-files]# service mysqld restart
Shutting down MySQL.. SUCCESS! 
Starting MySQL.. SUCCESS! 
[root@cdh03 support-files]#

10、修改随机登陆密码

[root@cdh03 support-files]# cd ..
[root@cdh03 mysql80]# cd bin
[root@cdh03 bin]# ./mysql -u root -p
Enter password:  输入刚刚的密码
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 8.0.21

Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.

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> 

11、修改密码为root

alter user  'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'root';

12、设置允许远程登陆

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> update user set user.Host='%'where user.User='root';
Query OK, 1 row affected (0.01 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)

退出

quit

重启

[root@cdh03 bin]# service mysqld restart
Shutting down MySQL.. SUCCESS! 
Starting MySQL.. SUCCESS! 
[root@cdh03 bin]# 
#查看mysql是否区分大小写
mysql> show variables like "%case%" ;
+------------------------+-------+
| Variable_name          | Value |
+------------------------+-------+
| lower_case_file_system | OFF   |
| lower_case_table_names | 1     |
+------------------------+-------+
2 rows in set (0.01 sec)

 

win下默认值是1,mac是2,linux是0。

0:区分大小写

1:不区分

2:部分区分

注:

#创建表
CREATE DATABASE scm DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci;

#创建用户并赋权
 GRANT ALL ON scm.* TO 'scm'@'%' IDENTIFIED BY 'scm';
报错:
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
查看权限规则
SHOW VARIABLES LIKE 'validate_password%';

#查看权限是否正确
SHOW GRANTS FOR 'myscm'@'%';
+------------------------------------------------+
| Grants for myscm@%                             |
+------------------------------------------------+
| GRANT USAGE ON *.* TO 'myscm'@'%'              |
| GRANT ALL PRIVILEGES ON `scm`.* TO 'myscm'@'%' |
+------------------------------------------------+


关于 mysql 密码策略相关参数;
1)、validate_password_length  固定密码的总长度;
2)、validate_password_dictionary_file 指定密码验证的文件路径;
3)、validate_password_mixed_case_count  整个密码中至少要包含大/小写字母的总个数;
4)、validate_password_number_count  整个密码中至少要包含阿拉伯数字的个数;
5)、validate_password_policy 指定密码的强度验证等级,默认为 MEDIUM;
关于 validate_password_policy 的取值:
0/LOW:只验证长度;
1/MEDIUM:验证长度、数字、大小写、特殊字符;
2/STRONG:验证长度、数字、大小写、特殊字符、字典文件;
6)、validate_password_special_char_count 整个密码中至少要包含特殊字符的个数;

set global validate_password_policy=LOW;
set global validate_password_length=1;

CREATE DATABASE scm DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci;
GRANT ALL ON scm.* TO 'myscm'@'%' IDENTIFIED BY 'myscm';
CREATE DATABASE metastore DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci;
GRANT ALL ON metastore.* TO 'metastore'@'%' IDENTIFIED BY 'metastore';

 

 

posted @ 2020-08-08 00:20  桥头堡洗脚城  阅读(299)  评论(0编辑  收藏  举报