Mysql 8.X 安装步骤

1、下载

#用wget慢 ,而且下载下来的文件解压有异常,推荐直接用讯雷下载,这里我己下载好上传了,可直接用。
wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.11-linux-glibc2.12-i686.tar.gz

2、解压到/usr/local目录

tar -zxvf mysql-8.0.11-linux-glibc2.12-i686.tar.gz -C /usr/local

3、进入/usr/local目录

#1、重命名
[root@sl local]#mv mysql-8.0.11-linux-glibc2.12-i686 mysql
#2、或建立软链接
[root@sl local]#ln -s mysql-8.0.11-linux-glibc2.12-i686 mysql

4、创建数据存储目录

[root@sl local]#mkdir -p /home/mysql/data

5、创建用户组,并将用户添加到用户组

[root@sl local]# groupadd mysql
[root@sl local]# useradd -g mysql mysql

6、给mysql目录分配权限

[root@sl local]# chown -R mysql.mysql /usr/local/mysql/

7、初始化,初始化结果中会给一个初始密码,用这个密码登录数据库

#进入mysql目录
[root@sl mysql]# cd /usr/local/mysql/

#执行安装初始化命令  --user指定用户,--basedir指定安装目录 ,--lower_case_table_name忽略大小写敏感,--datadir指定数据存储目录
[root@sl mysql]# bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --lower_case_table_names=1 --datadir=/home/mysql/data
2020-08-24T01:41:20.975550Z 0 [System] [MY-013169] [Server] /usr/local/mysql/bin/mysqld (mysqld 8.0.11) initializing of server in progress as process 23794
2020-08-24T01:41:27.544869Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: gs)u&wChy7rB
2020-08-24T01:41:29.268049Z 0 [System] [MY-013170] [Server] /usr/local/mysql/bin/mysqld (mysqld 8.0.11) initializing of server has completed
 

8、配置mysql启动

[root@sl mysql]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld 
[root@sl mysql]# chkconfig --add mysqld
[root@sl mysql]# chkconfig --list mysqld
mysqld         	0:关闭	1:关闭	2:启用	3:启用	4:启用	5:启用	6:关闭
[root@sl mysql]# 
[root@sl mysql]# vi /etc/profile
#在最后添加环境配置
export PATH=$PATH:/usr/local/mysql/bin:/usr/local/mysql/lib
export PATH

[root@sl mysql]# source /etc/profile
 

9、配置my.cn(不知道为什么该版本为什么安装时不会初始化my.cn所以要手工添 加)

[root@sl mysql]# vi /etc/my.cnf 

[mysqld]
basedir = /usr/local/mysql
datadir = /home/mysql/data
socket = /usr/local/mysql/mysql.sock
character-set-server=utf8
port = 3506
lower_case_table_names = 1
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
[client]
socket = /usr/local/mysql/mysql.sock
default-character-set=utf8

10、启动mysql,并登录mysql

[root@sl mysql]# service mysqld start
Starting MySQL. SUCCESS! 

#登录,但这里登录不了,失效果,不知道是不是第一次密码输错了的原因导致的。
[root@sl mysql]# mysqladmin - u root -p
Enter password: 
mysqladmin: connect to server at 'localhost' failed
error: 'Your password has expired. To log in you must change it using a client that supports expired passwords.'

 

12、如果密码用不了,请参照如下文章,无密码登录重新修改密码

https://blog.csdn.net/songling515010475/article/details/108194714

 

13、开启mysql远程连接

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> select 'host' from user where user='root';
+------+
| host |
+------+
| host |
+------+
1 row in set (0.00 sec)

mysql> update user set host = '%' where user='root';
Query OK, 1 row affected (0.09 sec)
Rows matched: 1  Changed: 1  Warnings: 0

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


mysql> select host,user from user;
+-----------+------------------+
| host      | user             |
+-----------+------------------+
| %         | root             |
| localhost | mysql.infoschema |
| localhost | mysql.session    |
| localhost | mysql.sys        |
+-----------+------------------+
4 rows in set (0.00 sec)

 

14、Mysql下载

https://download.csdn.net/download/songling515010475/12741738

你可能感兴趣的:(MYSQL,Linux,linux,运维,mysql)