centos7安装MySQL

1、mysql的/etc/my.cnf配置如下

[mysqld]
# 设置3306端口
port=3306
# 设置mysql的安装目录
basedir=/var/mysql/mysql-8.0.21
# 设置mysql数据库的数据的存放目录
datadir=/var/mysql/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
[mysql]
# 设置mysql客户端默认字符集
default-character-set=utf8
[client]
# 设置mysql客户端连接服务端时默认使用的端口
port=3306
default-character-set=utf8

ALTER USER ‘root’@‘localhost’ IDENTIFIED WITH mysql_native_password BY ‘123456’;

ALTER USER ‘root’@’%’ IDENTIFIED WITH mysql_native_password BY ‘123456’;

安装操作记录:
1、将安装包文件mysql-8.0.21-el7-x86_64.tar.gz上传解压后:
tar -zxvf mysql-8.0.21-el7-x86_64.tar.gz

[root@localhost mysql]# ll
drwxr-xr-x. 9  7161 31415       129 6月  17 03:15 mysql-8.0.21-el7-x86_64
-rw-r--r--. 1 root  root  586026623 9月   1 10:48 mysql-8.0.21-el7-x86_64.tar.gz
drwxrwxrwx. 2 mysql mysql         6 9月   1 10:43 mysqldb 
2、#没有mysqldb文件夹就创建mysqldb文件夹
mkidr mysqldb

3、#重命名
[root@localhost mysql]# mv mysql-8.0.21-el7-x86_64 mysql-8.0.21

4、#修改配置文件my.cnf
[root@localhost mysql]# vi /etc/my.cnf
#在文件中填入以下内容配置
[mysqld]
# 设置3306端口
port=3306
# 设置mysql的安装目录,就是你解压后的文件夹
basedir=/var/mysql/mysql-8.0.21
# 设置mysql数据库的数据的存放目录,我们刚刚创建的
datadir=/var/mysql/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
[mysql]
# 设置mysql客户端默认字符集
default-character-set=utf8
[client]
# 设置mysql客户端连接服务端时默认使用的端口
port=3306
default-character-set=utf8

5、#填入后保存退出

6、初始化mysql
[root@localhost mysql]# cd mysql-8.0.21/
[root@localhost mysql-8.0.21]# cd bin/
[root@localhost bin]# ./mysqld --initialize --console
2020-09-01T02:54:46.118209Z 0 [System] [MY-013169] [Server] /var/mysql/mysql-8.0.21/bin/mysqld (mysqld 8.0.21) initializing of server in progress as process 1874
2020-09-01T02:54:46.119599Z 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-09-01T02:54:46.127923Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2020-09-01T02:54:46.663758Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2020-09-01T02:54:47.968500Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: 9>aWKtu3k9iU

7、记住初始化mysql时的root密码: 9>aWKtu3k9iU,可以复制粘贴出来

[root@localhost bin]# cd ..
[root@localhost mysql-8.0.21]# cd support-files/

8、启动MySQL
[root@localhost support-files]# ./mysql.server start
Starting MySQL.Logging to '/var/mysql/mysqldb/localhost.localdomain.err'.
 ERROR! The server quit without updating PID file (/var/mysql/mysqldb/localhost.localdomain.pid).

9、报错(说没有文件)/var/mysql/mysqldb/localhost.localdomain.pid,那就进入到对应的目录,创建对应的文件
cd /var/mysql/mysqldb/
[root@localhost mysqldb]# touch localhost.localdomain.pid

10、回到mysql的根目录
[root@localhost mysqldb]# cd /var/mysql/

11、分配权限
[root@localhost mysql] chmod -R 777 /var/mysql/

12、再次启动mysql
[root@localhost mysql]# cd mysql-8.0.21/
[root@localhost mysql-8.0.21]# cd support-files/
[root@localhost support-files]# ./mysql.server start
Starting MySQL.. SUCCESS! 

13、将启动文件复制到mysqld中后重启
[root@localhost support-files]# cp mysql.server /etc/init.d/mysqld
[root@localhost support-files]# service mysqld restart
Shutting down MySQL.. SUCCESS! 
Starting MySQL.. SUCCESS! 

14、修改root账号的登录密码
[root@localhost support-files]# cd ..
[root@localhost mysql-8.0.21]# cd bin/

[root@localhost bin]# ./mysql -u root -p
#这里需要填入刚刚初始化时的密码
Enter password: 

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
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.

#修改root账号的登录密码,我这里设置为123456,
mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '123456';
Query OK, 0 rows affected (0.00 sec)

#更改用户
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.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

#刷新权限
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

#刷新权限后退出
mysql> quit
Bye

#最后再重启mysql
[root@localhost bin]# service mysqld restart
Shutting down MySQL.. SUCCESS! 
Starting MySQL.. SUCCESS! 
[root@localhost bin]# 

15、到这里,我们就安装mysql完毕了,如果是使用客户端连接软件连接mysql,还需要放开3306端口的防火墙(在my.cnf配置文件中配置的端口号)
#开放端口3306
firewall-cmd --zone=public --add-port=3306/tcp --permanent 
#重启防火墙
firewall-cmd --reload
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值