CentOS 8安装MySQL-5.1.55(二进制.tar.gz安装)遇到的问题及其解决
一、版本选取
官网下载地址。选取操作系统版本为Linux-Generic、64位(如上图),Compressed TAR Archive 二进制发行包(如下图)。
![](https://i-blog.csdnimg.cn/blog_migrate/541f8037b595b457448a6c6e9aa81fcb.png#pic_center)
![](https://i-blog.csdnimg.cn/blog_migrate/cc7bb0f6da76988effd46e1af801da11.png#pic_center)
具体安装过程参考这篇博客。
二、安装过程错误
执行安装命令
./scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql-5.1.55 --datadir=/usr/local/mysql-5.1.55/data
时出现错误:./bin/my_print_defaults: error while loading shared libraries: libnsl.so.1: cannot open shared object file: No such file or directory. 即共享对象文件libnsl.so.1找不到。这里不同的人的系统缺少的可能是不同的文件。
![](https://i-blog.csdnimg.cn/blog_migrate/f33f1f899a548df5884e4fd41144cbd1.png#pic_center)
解决办法:先找找系统中有没有这个库,执行命令rpm -qa | grep libnsl
进行查找。没找到说明需要安装,找到了说明需要升级。执行yum install -y libnsl
命令进行安装或者升级,然后再尝试执行之前的命令安装mysql,注意:mysql安装过程中只要没有[ERROR]开头的提示基本上代表成功安装了。
![](https://i-blog.csdnimg.cn/blog_migrate/6b248a83e4a6b55ace4e95a1d1507eb2.png#pic_center)
三、启动过程错误
使用mysql -uroot -p
登录mysql时报缺少依赖的错误:mysql: error while loading shared libraries: libncursesw.so.5: cannot open shared object file: No such file or directory.
一般而言CentOS 8是自带这个库的,只是缺少同名的链接。通过find / -name "libncursesw*"
命令查找libncursesw相关的文件位置,接着创建软链接即可。如找到文件的位置为/usr/lib64/libncursesw.so.6.1,使用命令:
ln -s /usr/lib64/libncursesw.so.6.1 /lib64/libncursesw.so.5
在指定位置(末尾的/lib64/)创建软链接。至于指定位置的获取,我们可以使用ldd mysql
命令查看mysql的依赖来源,来源的位置就是我们需要指定的位置,如图。当然也可以检查还有没有找不到的依赖(not found)。
![](https://i-blog.csdnimg.cn/blog_migrate/0e093ad943c5c9d936c9fa1ae36c0d72.png#pic_center)
如果find命令找不到相关文件的,需要下载这个库再进行之后的操作,这里省略。
四、修改密码问题
对于5.1.55版本,上述博客教程当中给出的修改密码方法不适用。
正解:
- 使用root账户无密码登入mysql之后,执行
set password=password('123456789');
语句修改密码为123456789
- 执行flush privileges;
语句
- 使用quit
命令退出mysql
此时,通过service mysqld restart
命令重启mysql服务进程,再次登录即可。
如果按照错误教程乱改密码,导致登不进(Access denied for user ‘root’@‘localhost’)或者登进去发现没有mysql数据库(即改不了位于mysql数据库当中的user表,执行use mysql报 Access denied for user ‘’@’localhost’ to database ‘mysql’),考虑依次执行以下步骤:
- 退出mysql,通过
vim /etc/my.cnf
修改配置文件,在[mysqld]所属区域添加skip-grant-tables,进入特殊模式允许跳过密码登录
- 重启mysql服务进程
- 无密码登录mysql(mysql -uroot -p
),通过show tables;
语句可见有mysql数据库,use mysql
命令进入之
- 还原之前对user表的修改(update user set password='' where user='root';
)
- 返回正常模式,即执行flush、退出mysql、去除添加的skip-grant-tables、重启mysql服务进程
这时基本上是恢复到了乱改密码之前的状态了,可以通过正解步骤修改密码。