Centos8 安装Mysql8

2020-11-18  本文已影响0人  ArthurIsUsed

官网下载二进制压缩包, 下载地址

下载好后,通过FTP传到虚拟机

cd /usr/local/
tar -xvf mysql-8.0.22-linux-glibc2.12-x86_64.tar.xz
mv mysql-8.0.22-linux-glibc2.12-x86_64 mysql-8.0.22

添加用户组

groupadd mysql
useradd -r -g mysql mysql

进入文件夹,添加data目录

cd  /usr/local/mysql-8.0.22
mkdir data tmp 
chmod 777 ./data ./tmp

新建配置文件

cd support-files/
vim my-default.cnf

添加以下内容

[mysqld]
basedir = /usr/local/mysql-8.0.22
datadir = /usr/local/mysql-8.0.22/data
port = 3306
socket = /usr/local/mysql-8.0.22/tmp/mysql.sock
lower_case_table_names=1


[client]
default-character-set=utf8
socket= /usr/local/mysql-8.0.22/tmp/mysql.sock


[mysql]
default-character-set=utf8
socket= /usr/local/mysql-8.0.22/tmp/mysql.sock

修改MySQL目录为MySQL用户

cd /usr/local/mysql-8.0.22/
chown -R mysql:mysql ./

切换到mysql-8.0.22目录,初始化数据库

bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql-8.0.22 --datadir=/usr/local/mysql-8.0.22/data 

得到以下信息, root密码为: hf7;jwsAOUr4

2020-11-17T15:55:35.313386Z 0 [System] [MY-013169] [Server] /usr/local/mysql-8.0.22/bin/mysqld (mysqld 8.0.22) initializing of server in progress as process 9854
2020-11-17T15:55:35.353782Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2020-11-17T15:55:37.125873Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2020-11-17T15:55:39.595056Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: hf7;jwsAOUr4

切换到support-files目录

cp mysql.server /etc/init.d/mysql
chmod +x /etc/init.d/mysql
chkconfig --add mysql
chkconfig --list mysql (检查是否启动成功)

启动

/etc/init.d/mysql start

/etc/init.d/mysql: line 239: my_print_defaults: command not found
/etc/init.d/mysql: line 259: cd: /usr/local/mysql: No such file or directory
Starting MySQL ERROR! Couldn't find MySQL server (/usr/local/mysql/bin/mysqld_safe)


复制一份配置到/etc目录下

cp my-default.cnf /etc/my.cnf
chmod 664 /etc/my.cnf

继续报错

[root@localhost mysql-8.0.22]# /etc/init.d/mysql  start
Starting MySQL.Logging to '/usr/local/mysql-8.0.22/data/localhost.localdomain.err'.
 ERROR! The server quit without updating PID file (/usr/local/mysql-8.0.22/data/localhost.localdomain.pid).

试过所有百度到的方法,把mysql-8.0-22目录改成mysql,并删除/etc目录下的my.cnf,再次启动却成功了。活见鬼!

链接MySQL,修改root密码

ln  -s   /usr/local/mysql/bin/mysql    /usr/bin
mysql -u root -p

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

查看MySQL依赖

[root@localhost bin]# ldd mysql
    linux-vdso.so.1 (0x00007fff140e8000)
    libpthread.so.0 => /lib64/libpthread.so.0 (0x00007f16953ba000)
    librt.so.1 => /lib64/librt.so.1 (0x00007f16951b1000)
    libcrypto.so.1.1 => /usr/local/mysql/bin/./../lib/private/libcrypto.so.1.1 (0x00007f1694d00000)
    libssl.so.1.1 => /usr/local/mysql/bin/./../lib/private/libssl.so.1.1 (0x00007f1694a70000)
    libdl.so.2 => /lib64/libdl.so.2 (0x00007f169486c000)
    libresolv.so.2 => /lib64/libresolv.so.2 (0x00007f1694655000)
    libtinfo.so.5 => not found
    libstdc++.so.6 => /lib64/libstdc++.so.6 (0x00007f16942c0000)
    libm.so.6 => /lib64/libm.so.6 (0x00007f1693f3e000)
    libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00007f1693d26000)
    libc.so.6 => /lib64/libc.so.6 (0x00007f1693964000)
    /lib64/ld-linux-x86-64.so.2 (0x00007f16955da000)

安装一个依赖

sudo dnf install ncurses.x86_64

结果还是不行,拿个Fedoras的文件试试, 结果成功

sudo ln -s  /usr/lib64/libtinfo.so.6.1 /usr/lib64/libtinfo.so.5

连接MySQL,修改root密码



alter user 'root'@'localhost' identified by 'root';(重置为root)
flush privileges;

use mysql
update user set host = '%' where user ='root'; 
flush privileges; 
上一篇下一篇

猜你喜欢

热点阅读