1、下载mysql包
1.1 进入官网选择社区版mysql
mysql官网网址:MySQL
1.2 选择 MySQL Community Server 下载
1.3 选择操作系统类型和MySQL版本
1.4 开始下载
1.4.1 Linux中下载MySQL
1.5 在Linux中输入:wget+上面所复制的链接地址
(我这里下载的是Linux8.0.30版本的mysql所以我在Linux中的下载命令为:
wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.30-linux-glibc2.12-x86_64.tar.xz)
wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.30-linux-glibc2.12-x86_64.tar.xz
1.6 解压msyql包
1.6.1 首先要将mysql包移动到到自定义的安装目录下
mv mysql-8.0.30-linux-glibc2.12-x86_64.tar.xz /usr/local/soft/
1.6.2 然后进行解压,注意这个文件是.xz文件
注意:-Jxvf 中的J为大写的
tar -Jxvf mysql-8.0.30-linux-glibc2.12-x86_64.tar.xz
我这里的文件是.xz文件,如果你下载的文件是**.tar.gz文件的话用 :tar -zxvf +文件命令
给解压后的文件重命名
mv mysql-8.0.30-linux-glibc2.12-x86_64.tar.xz mysql8
2 、配置
2.1 编译配置文件my.cnf(这个文件一般是默认存在的,不需要自己手动创建,mysql在初始化是会去寻找这个配置文件,如果没有有则是默认的系统配置)
在/etc文件夹下配置my.cnf文件
1| vim /etc/my.cnf
在my.cnf文件中加入以下配置:
[mysqld]
# 设置3306端口
port=3306
# 设置mysql的安装目录
basedir=/usr/local/soft/mysql8
# 设置mysql数据库的数据的存放目录
datadir=/usr/local/soft/mysql8/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.2 创建用户并且初始化
在mysql的安装目录下新建文件data
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/soft/mysql8/
初始化mysql数据库
记住mysql的初始密码
3、启动mysql
3.1 启动mysql 如果报错,看下面4报错模块
[mysql@wnode1 mysql8]$ cd support-files/
[mysql@wnode1 support-files]$ ls
mysqld_multi.server mysql-log-rotate mysql.server
[mysql@wnode1 support-files]$ ./mysql.server start
Starting MySQL SUCCESS!
[mysql@wnode1 support-files]$
3.2 连接mysql、修改密码
[root@wnode1 mysql8]#
[root@wnode1 mysql8]#
[root@wnode1 mysql8]#
[root@wnode1 mysql8]# ./bin/mysql -h 127.0.0.1 -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.30 MySQL Community Server - GPL
Copyright (c) 2000, 2022, Oracle and/or its affiliates.
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用户的密码设置为 123456
alter user 'root'@'localhost' identified by '123456';
4、报错模块(其他配置)
注意当你mysql安装的路径不是/usr/local/mysql 时启动可能会报错
这时我们需要修改下mysql启动脚本的配置文件
4.1 修改mysql安装路径support-files目录下的mysql.server文件
[root@wnode1 mysql8]#
[root@wnode1 mysql8]#
[root@wnode1 mysql8]#
[root@wnode1 mysql8]# su mysql
[mysql@wnode1 mysql8]$ cd support-files/
[mysql@wnode1 support-files]$ vim mysql.server
4.2、修改mysql安装路径support-files目录下的mysqld_multi.server文件
[mysql@wnode1 support-files]$ vim mysqld_multi.server
5、允许其他ip可以连接mysql
(例如想用Navicat连接mysql如果不设置会报如下图的错)
用root登录mysql: ./bin/mysql -h 127.0.0.1 -u root -p
切换到mysql数据库: use mysql
更改root的权限,允许其他IP地址登录: update user set host = "%" where user = "root";
查看表数据: select host, user from user;
刷新权限: 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>
————————————————
版权声明:本文为CSDN博主「慧梦之旅」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/qq_35330159/article/details/103236316
版权归原作者 数加头子 所有, 如有侵权,请联系我们删除。