Centos8安装mysql8的详细过程(免安装版/或者二进制包方式安装)

作者:chunchun868 时间:2024-01-27 02:51:17 

二进制包方式安装

一、首先检查服务器上是否安装有mysql:

第一步:查看mysql安装版本
rpm -qa|grep -i mysql

第二步:卸载Mysql
rpm -ev --nodeps 【上一步查询到的mysql版本名称】

最后删除关于mysql相关的文件夹:查找根目录下所有者是mysql和有mysql名称的文件
find / -user mysql
find / -name mysql
把查找出的目录文件删除:rm -rf 路径

二、开始安装配置mysql

mysql-8.0.30-linux-glibc2.12-x86_64.tar.xz

网址:MySQL :: Download MySQL Community Server (Archived Versions)

Centos8安装mysql8的详细过程(免安装版/或者二进制包方式安装)

上传到服务器上,解压,然后改名,copy到想要的安装目录(/usr/local/)

目录计划:

安装目录:/usr/local/mysql

data 目录:/data/mysql/data/

日志位置:/data/mysql/mysql_error.err

xz -d  tar xvf mysql-8.0.30-linux-glibc2.12-x86_64.tar.xz
tar xvf mysql-8.0.30-linux-glibc2.12-x86_64.tar
mv mysql-8.0.30-linux-glibc2.12-x86_64 mysql
mv mysql /usr/local/

创建mysql用户和用户组

groupadd mysql
useradd -r -g mysql -s /bin/false mysql

将安装目录所有者及所属组改为mysql ,并创建相关文件夹

cd /usr/local/
chown -R mysql:mysql /usr/local/mysql/
ll
mkdir -p /data/mysql/{data,backup,scripts,binlog}
ll /data/mysql/
chown -R mysql:mysql /data/mysql/

添加环境变量,并修改my.cnf配置文件

echo "export PATH=$PATH:/usr/local/mysql/bin"  >>  /etc/profile
source /etc/profile
vi /etc/my.cnf
[mysqld]
user=mysql
port=3306
#basedir=/data/mysql
datadir = /data/mysql/data/
default_authentication_plugin=mysql_native_password
log_error=/data/mysql/mysql_error.err
max_connections=10000
max_connect_errors=10
character-set-server=utf8mb4
default-storage-engine=INNODB
default_authentication_plugin=mysql_native_password
[mysql]
default-character-set=utf8mb4

初始化mysql数据库

mysqld --initialize --user=mysql

/data/mysql/mysql_error.err里记录了 mysql初始密码

Centos8安装mysql8的详细过程(免安装版/或者二进制包方式安装)

将mysql加入到服务,并设置开机自启,启动mysql

cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
chkconfig mysqld on
systemctl start mysqld

连接mysql

遇到报错

[root@localhost mysql]# mysql -uroot -p
mysql: error while loading shared libraries: libtinfo.so.5: cannot open shared object file: No such file or directory

解决方案:

[root@localhost mysql]# sudo ln -s /usr/lib64/libtinfo.so.6.1 /usr/lib64/libtinfo.so.5

再次连接SQL

[root@localhost mysql]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.30

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> alter user root@localhost identified by '111111';
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 host='%' where 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> grant all privileges on *.* to 'root'@'%' with grant option;
Query OK, 0 rows affected (0.00 sec)#刷新权限
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)
mysql> quit

#刷新权限

systemctl restart mysql
or
service mysql restart

重启服务且测试

systemctl restart mysqlorservice mysql restart

查看防火墙开放端口

firewall-cmd --list-all

在防火墙中将3306端口开放

firewall-cmd --zone=public --add-port=3306/tcp --permanent

firewall-cmd --reload

//--permanent为永久生效,没有此参数 服务器重启后配置失效

在Navicat上测试连接

重启linux后测试自启动(可选)
reboot

测试mysql服务是否自启动

systemctl status mysql

参考文献:

(1条消息) Linux下免安装版本的mysql5.7

来源:https://www.cnblogs.com/chunchun868/p/16869780.html

标签:Centos,安装,mysql8
0
投稿

猜你喜欢

  • 在ASP中使用SQL语句之6:存储过程查询

    2007-08-11 12:44:00
  • mysql存储过程学习总结

    2011-07-04 12:03:53
  • 基于python制作简易版学生信息管理系统

    2022-04-15 18:39:45
  • vue项目移动端实现ip输入框问题

    2024-05-09 09:20:58
  • python在Windows下安装setuptools(easy_install工具)步骤详解

    2022-10-18 19:40:23
  • 对dataframe进行列相加,行相加的实例

    2023-07-24 16:57:59
  • Php+SqlServer实现分页显示

    2023-11-20 05:02:24
  • vue日期时间工具类详解

    2024-06-07 16:06:22
  • vue 自定义右键样式的实例代码

    2023-07-02 16:33:34
  • python基于 Web 实现 m3u8 视频播放的实例

    2022-06-15 22:16:40
  • JavaScript ES6中const、let与var的对比详解

    2024-05-22 10:37:36
  • 使用ODBC接口访问MySQL

    2009-02-13 13:59:00
  • go语言操作redis连接池的方法

    2024-02-01 23:46:53
  • JQuery判断radio(单选框)是否选中和获取选中值方法总结

    2024-04-19 10:24:11
  • 跟老齐学Python之通过Python连接数据库

    2024-01-13 09:12:30
  • 栅格:灵活应变

    2008-07-22 12:22:00
  • Python中的文本相似度的计算方法总结

    2021-02-08 08:40:37
  • 浅谈pandas中shift和diff函数关系

    2022-11-15 08:48:42
  • vue货币过滤器的实现方法

    2024-05-09 10:40:58
  • python爬虫开发之PyQuery模块详细使用方法与实例全解

    2021-05-28 20:54:29
  • asp之家 网络编程 m.aspxhome.com