linux下安装mysql 8.0

linux下安装mysql 8.0
1、下载mysql包
1.1、进入官网选择下载社区版mysql如下图

1.2、选择mysql community server 下载

在这里插入图片描述

1.3、选择操作系统类型及下载的版本并点击下载

在这里插入图片描述

1.4、如下图点击鼠标右键复制下载连接

在这里插入图片描述

1.5、然后在Linux中输入 wget + 下载连接地址开始下载mysql 我这里为
wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.18-linux-glibc2.12-x86_64.tar.xz

在这里插入图片描述

2、解压及配置
2.1、将下载的mysql包复制到对应的安装目录下bin解压

在这里插入图片描述

2.2、解压mysql包

跳转到mysql包的目录下输入如下命令解压文件
tar -Jxvf mysql-8.0.18-linux-glibc2.12-x86_64.tar.xz 输入
注意我这里下载的是**.tar.xz格式的包所以用tar -Jxvf 命令如果是**.tar.gz的请使用 tar -zxvf 命令
解压后会的到如下图的文件夹并将其重命名
在这里插入图片描述

2.3、创建配置文件

注意这个步骤可以省略!mysql在初始化数据库时会去寻找/etc/my.cnf这个配置文件,当找不到这个配置文件是将使用系统默认的配置,来初始化mysql数据库。
在/etc 目录下创建 my.cnf 配置文件内容如下:

[mysqld]
# 设置3306端口
port=3306
# 设置mysql的安装目录
basedir=/usr/local/mysql
# 设置mysql数据库的数据的存放目录
datadir=/usr/local/mysql/data
# 允许最大连接数/
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
user=mysql

2.4、创建用户并初始化mysql

在mysql安装目录下创建数data目录

[root@ecs-s6-medium-2-linux-20191122095023 mysql]# mkdir data

创建用户组及用户并给权限

[root@ecs-s6-medium-2-linux-20191122095023 mysql]# groupadd mysql
[root@ecs-s6-medium-2-linux-20191122095023 mysql]# useradd -rg mysql mysql
[root@ecs-s6-medium-2-linux-20191122095023 mysql]# chown -R mysql:mysql /usr/local/mysql/

初始化mysql数据库

[root@ecs-s6-medium-2-linux-20191122095023 mysql]# pwd
/usr/local/mysql
[root@ecs-s6-medium-2-linux-20191122095023 mysql]# su mysql
bash-4.1$ ./bin/mysqld --initialize
2019-11-25T02:01:48.485052Z 0 [System] [MY-013169] [Server] /usr/local/mysql/bin/mysqld (mysqld 8.0.18) initializing of server in progress as process 15896
2019-11-25T02:01:48.485955Z 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.
2019-11-25T02:01:51.491886Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: >wgM7>hh*L;=
bash-4.1$

注意:如下图框框的内容为root用户的初始密码,得记住
在这里插入图片描述

3、启动mysql
3.1、启动mysql服务 注意:如果报错看第4点!
bash-4.1$ cd support-files/
bash-4.1$ ls
mysqld_multi.server  mysql-log-rotate  mysql.server
bash-4.1$ ./mysql.server start
Starting MySQL.                                            [  OK  ]
bash-4.1$
3.2、连接mysql并更改密码

连接mysql

[root@ecs-s6-medium-2-linux-20191122095023 mysql-8.0]#
[root@ecs-s6-medium-2-linux-20191122095023 mysql-8.0]# pwd
/usr/local/mysql
[root@ecs-s6-medium-2-linux-20191122095023 mysql-8.0]# ./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.18

Copyright (c) 2000, 2019, 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>

将root用户的密码设置为 root@123456

mysql>
mysql> alter user 'root'@'localhost' identified by 'root@123456';
Query OK, 0 rows affected (0.02 sec)

mysql>

3.3、将mysql设置为服务方式启动

为mysql.server文件在/etc/init.d目录下创建软连接并重新启动服务器

[root@ecs-s6-medium-2-linux-20191122095023 init.d]# ln -s /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
[root@ecs-s6-medium-2-linux-20191122095023 init.d]#
[root@ecs-s6-medium-2-linux-20191122095023 init.d]# service mysqld stop
Shutting down MySQL..                                      [  OK  ]
[root@ecs-s6-medium-2-linux-20191122095023 init.d]# service mysqld start
Starting MySQL.                                            [  OK  ]
[root@ecs-s6-medium-2-linux-20191122095023 init.d]#

4、其他配置

注意当你mysql安装的路径不是/usr/local/mysql 时启动可能会报错
这时我们需要修改下mysql启动脚本的配置文件

4.1、修改mysql安装路径support-files目录下的mysql.server文件
bash-4.1$ vim mysql.server

在这里插入图片描述

4.1、修改mysql安装路径support-files目录下的mysqld_multi.server文件
bash-4.1$ vim mysqld_multi.server

在这里插入图片描述

5、设置允许其他IP也可以连接mysql
  1. 用root登录mysql: ./bin/mysql -u root -p
  2. 切换到mysql数据库: use mysql
  3. 更改root的权限,允许其他IP地址登录: update user set host = "%" where user = "root";
  4. 查看表数据: select host, user from user;
  5. 刷新权限: flush privileges;
[root@ecs-s6-medium-2-linux-20191122095023 mysql-8.0]#
[root@ecs-s6-medium-2-linux-20191122095023 mysql-8.0]# pwd
/usr/local/mysql
[root@ecs-s6-medium-2-linux-20191122095023 mysql-8.0]# ./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.18

Copyright (c) 2000, 2019, 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>
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>
mysql> update user set host = '%' where user = 'root';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0
mysql>
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)
mysql>
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql>

注意: 如果其他用户想允许其他IP登录也是这样设置

  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值