centeros8安装mysql-8.0.26

2021/7/28 19:40:41

本文主要是介绍centeros8安装mysql-8.0.26,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

1、下载最新mysql,当前最新版本为8.0.26,由于linux为64位的,则选择对应的版本,如下图

      在/usr/local文件夹下新建mysql,再下载到该目录,详细linux代码如下。

[root@localhost ~]# cd /usr/local
[root@localhost local]# mkdir mysql
[root@localhost local]# chmod 777 mysql
[root@localhost mysql]# wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.26-linux-glibc2.12-x86_64.tar.xz

2、下载完成后,执行解压

由于最新版本为xz,则先解压xz为tar,再解压tar,解压完成,修改解压后的文件夹名称为mysql-8.0.26,在mysql-8.0.26新增一个data文件夹用来存放mysql的数据库文件命令如下

[root@localhost mysql]# xz -d mysql-8.0.26-linux-glibc2.12-x86_64.tar.xz
[root@localhost mysql]# tar xvf mysql-8.0.26-linux-glibc2.12-x86_64.tar
[root@localhost mysql]# mv mysql-8.0.26-linux-glibc2.12-x86_64 mysql-8.0.26
[root@localhost mysql]# cd mysql-8.0.26
[root@localhost mysql-8.0.26]# mkdir data
[root@localhost mysql-8.0.26]# chmod 777 data

3、创建mysql用户组,mysql用户

[root@localhost mysql]# groupadd mysql
[root@localhost mysql]# useradd -g mysql mysql

4、将指定文件的拥有者改为指定的用户或组

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

 5、初始化安装

[root@localhost mysql]# cd /usr/local/mysql/mysql-8.0.26/bin
[root@localhost bin]# ./mysqld --user=mysql --basedir=/usr/local/mysql/mysql-8.0.26 --datadir=/usr/local/mysql/mysql-8.0.26/data/ --initialize
2021-07-27T06:53:51.876510Z 0 [System] [MY-013169] [Server] /usr/local/mysql/mysql-8.0.26/bin/mysqld (mysqld 8.0.26) initializing of server in progress as process 22784
2021-07-27T06:53:51.937081Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2021-07-27T06:53:52.342254Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2021-07-27T06:53:53.037476Z 0 [Warning] [MY-013746] [Server] A deprecated TLS version TLSv1 is enabled for channel mysql_main
2021-07-27T06:53:53.037667Z 0 [Warning] [MY-013746] [Server] A deprecated TLS version TLSv1.1 is enabled for channel mysql_main
2021-07-27T06:53:53.210327Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: 0/t9gJwjvp-&

注意看最后一句,把这个安装成功后生成的随机密码记录下来,留着后面登陆后修改;

6、创建mysql服务

由于mysql文件目录为非官方指定的安装目录,创建mysql服务的时候需要修改一下mysql.server,basedir以及datadir,修改为我们真实的目录。

basedir=/usr/local/mysql/mysql-8.0.26
datadir=/usr/local/mysql/mysql-8.0.26/data

 修改完成上传,继续执行如下命令

[root@localhost bin]# cd /usr/local/mysql/mysql-8.0.26
[root@localhost mysql-8.0.26]# cp -a ./support-files/mysql.server /etc/init.d/mysql
[root@localhost mysql-8.0.26]# chmod +x /etc/init.d/mysql
[root@localhost mysql-8.0.26]# chkconfig --add mysql

启动mysql服务 ,执行linux命令service mysql start

查看启动状态 service mysql status

将mysql命令添加到服务  ln -s /usr/local/mysql/mysql-8.0.20/bin/mysql /usr/bin

7、修改mysql默认密码以及开启远程连接

    用临时密码登录mysql  mysql -uroot -p

    mysql8修改密码有点奇葩,需要先置空再update;

中间有个小插曲,登陆MySQL的时候,报如下错误,

mysql: error while loading shared libraries: libtinfo.so.5: cannot open shared object file: No such file or directory

解决办法:
sudo ln -s /usr/lib64/libtinfo.so.6.1 /usr/lib64/libtinfo.so.5

8、修改防火墙开放3306端口

参考文章:https://www.cnblogs.com/kc19941205/p/14721580.html



这篇关于centeros8安装mysql-8.0.26的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程