linux安装mysql8.0.25

一、安装

准备工作

官网下载链接:https://dev.mysql.com/downloads/mysql/

linux安装mysql8.0.25

 

 

  

 

cd /usr/local
# 创建mysql目录
mkdir mysql
# 进入目录
cd mysql

将下载之后的包(mysql-8.0.25-linux-glibc2.12-x86_64.tar.xz) 上传到/usr/local/mysql 路径下

1、解压更新文件名

# 因为是xz文件,所以要先解压成tar
xz -d mysql-8.0.25-linux-glibc2.12-x86_64.tar.xz
# 解压tar包
tar -xvf mysql-8.0.25-linux-glibc2.12-x86_64.tar
# 更改文件名称,方便后续处理
mv mysql-8.0.25-linux-glibc2.12-i686 mysql-8.0.25
# 创建数据库,数据存储的目录
cd mysql-8.0.25

  

2、创建用户组授权

groupadd mysql
useradd
-g mysql mysql
chown mysql:mysql -R /usr/local/mysql/data/mysqldata
chmod 750 /usr/local/mysql/data/mysqldata/ -R

 

3、配置环境变量

vim /etc/profile
#在文件的最后一行增加 export PATH
=$PATH:自己的解压路径/bin:自己的解压路径/lib source /etc/profile

 

4、编辑配置文件(进入后i编辑,wq保存)

vim /etc/my.cnf

  替换文件内容

#2. 按insert 进入编辑模式 添加以下脚本
[mysql]
# 客户端默认字符集
default-character-set=utf8mb4
[client]
port=3306
socket=/var/lib/mysql/mysql.sock
[mysqld]
port=3306
server-id=3306
user=mysql
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
# 设置mysql的安装目录
basedir=/usr/local/mysql/mysql-8.0.25/ #你自己的安装路径
# 设置mysql数据库的数据的存放目录
datadir=/usr/local/mysql/data/mysqldata//mysql  #你自己创建的数据库文件存放路径
log-bin=/usr/local/mysql/data/mysqldata//mysql/mysql-bin
innodb_data_home_dir=/usr/local/mysql/data/mysqldata//mysql
innodb_log_group_home_dir=/usr/local/mysql/data/mysqldata//mysql
character-set-server=utf8mb4
lower_case_table_names=1
autocommit=1
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemd

[mysqld_safe]
#设置mysql数据库的日志及进程数据的存放目录
log-error=/usr/local/mysql/data/mysqldata//mysql/mysql.log
pid-file=/usr/local/mysql/data/mysqldata//mysql/mysql.pid


!includedir /etc/my.cnf.d

 

5、初始化数据库

cd /usr/local/mysql/mysql-8.0.25/bin/
./mysqld --defaults-file=/etc/my.cnf --basedir=/usr/local/mysql/mysql-8.0.25/ --datadir=/usr/local/mysql/data/mysqldata/mysql --user=mysql --initialize

#参数详解
--defaults-file=/etc/my.cnf 指定配置文件(一定要放在最前面,至少 --initialize 前面)
--user=mysql 指定用户(很关键)
--basedir=/home/mysql-8.0.25/ 指定安装目录
--datadir=/data/mysqldata/mysql/ 指定初始化数据目录

得到初始账号密码:

linux安装mysql8.0.25

 

 

 

 

 

  

初始化时有可能会出现以下异常,此异常大概率是因为在服务器是64位,而数据库下载了32位的

异常一:bash: bin/mysqld: /lib/ld-linux.so.2: bad ELF interpreter: No such file or d

异常二:bash: bin/mysqld: /lib/libnuma.so.1: bad ELF interpreter: No such file or d

解决方案一:执行以下命令,安装兼容程序

yum install xulrunner.i686
yum install -y libaio
yum install -y libaio.so.1
yum install -y libnuma.so.1

  

解决方案二:下载64位数据库,删除/usr/local/mysql/data中初始化出来的信息,重新执行步骤

6、复制mysql服务

cp /usr/local/mysql/mysql-8.0.25/support-files/mysql.server /etc/init.d/mysql
cp /usr/local/mysql/mysql-8.0.25/support-files/mysql.server /etc/init.d/mysqld

7、赋予权限,并增加/var/lib/mysql目录

# 检查一下/var/lib/mysql是否存在,否进行创建(目录和my.cnf保持一致)
mkdir /var/lib/mysql
chown 777 /etc/my.cnf
chmod +x /etc/init.d/mysql
chmod +x /etc/init.d/mysqld
chown -R mysql:mysql /var/lib/mysql/

 

8、启动mysql服务

service mysql start #systemctl mysql start 

 

 

 

二、操作数据库

  1、连接数据库

cd /usr/local/mysql/mysql-8.0.25/bin
./mysql -uroot -p

linux安装mysql8.0.25

 

 

 2、修改密码

# 修改root密码 修改root用户只能本地连接
ALTER USER root@localhost IDENTIFIED with mysql_native_password BY 新密码;
#刷新权限
flush privileges; 

3、设置远程访问

# 创建root用户任意远程访问
CREATE user root@%;
alter user root@% identified with mysql_native_password by 新密码;
flush privileges;
# 创建mysql用户任意远程访问
CREATE user mysql@%;
alter user root@% identified with mysql_native_password by 新密码;
flush privileges;

linux安装mysql8.0.25

4、授权

#将test库的所有权限赋予mysql用户
grant all privileges on test.* to "mysql"@"%";
#刷新权限
flush privileges;

 

 

 

三、开机自启动

 

#1.查看是否有mysql服务
chkconfig --list
#2.进入mysql软件目录,复制mysql.server文件到 /etc/rc.d/init.d目录下
cp /usr/local/mysql/mysql-8.0.25/support-files/mysql.server /etc/init.d/mysql
#3.给/etc/rc.d/init.d/mysql赋权可执行权限
chmod  +x  /etc/rc.d/init.d/mysql
#4.添加mysql服务
chkconfig --add mysql
#5.使mysql服务开机自启
chkconfig --level 345 mysql on
#6.查看MySQL服务 ,重启服务器,测试是否成功。
chkconfig --list

 

本文摘抄自:https://blog.csdn.net/qq_40869428/article/details/117226927,如有侵权,请联系删除

linux安装mysql8.0.25

上一篇:连接mysql是遇到的问题和方法。


下一篇:启动项目链接SQLserver报错The server selected protocol version TLS10 is not accepted by client preferences [TLS12]