linux下如何安装新版的mysql

本文提供了一套详细的步骤,指导Linux用户如何从已安装的MySQL版本升级到新版本,包括卸载旧版、安装新版、启动数据库以及解决安装过程中可能出现的常见问题。同时介绍了MySQL的登录方式、生成my.cnf文件、更改root用户密码等关键操作,确保用户能够顺利进行MySQL版本更新。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

http://blog.chinaunix.net/uid-77311-id-3484383.html

安装linux的时候,若选择了mysql,安装系统的时候会自动安装mysql,若想安装新版本的mysql,如要将之前的安装的删除掉.
下面介绍如何删除之前的mysql重新安装新版本的mysql.

1.找到之前安装mysql
#rpm -qa|grep -i mysql
php-mysql-5.1.6-5.el5
MySQL-python-1.2.1-1
mysql-bench-5.0.22-2.1
mysql-5.0.22-2.1
mysql-server-5.0.22-2.1
mysql-connector-odbc-3.51.12-2.2
mod_auth_mysql-3.0.0-3.1
mysql-devel-5.0.22-2.1
qt-MySQL-3.3.6-20.el5
perl-DBD-MySQL-3.0007-1.fc6

2.将以上的安装包逐个删除掉,将依赖的包也相应的删除掉
rpm -e php-mysql-5.1.6-5.el5
rpm -e MySQL-python-1.2.1-1
rpm -e mysql-bench-5.0.22-2.1
rpm -e mysql-5.0.22-2.1
rpm -e mysql-server-5.0.22-2.1
rpm -e mysql-connector-odbc-3.51.12-2.2
rpm -e mod_auth_mysql-3.0.0-3.1
rpm -e mysql-devel-5.0.22-2.1
rpm -e qt-MySQL-3.3.6-20.el5
rpm -e perl-DBD-MySQL-3.0007-1.fc6

如果因存在依赖关系而不能卸载,rpm将给予提示并停止卸载。你可以使用如下的命令来忽略依赖关系,直接开始卸载:

rpm -e [package name] --nodeps

直到如下命令没有任何结果输出为止
#rpm -qa|grep -i mysql 

3.安装新版本的mysql
[root@hxl ftp]# rpm -ivh MySQL-server-5.5.29-2.rhel5.i386.rpm
Preparing...                ########################################### [100%]
ls: /var/lib/mysql/*.err: No such file or directory
ls: /var/lib/mysql/*.err: No such file or directory
   1:MySQL-server           ########################################### [100%]

......

A RANDOM PASSWORD HAS BEEN SET FOR THE MySQL root USER !
You will find that password in '/root/.mysql_secret'.

You must change that password on your first connect,
no other statement but 'SET PASSWORD' will be accepted.
See the manual for the semantics of the 'password expired' flag.

......
[root@hxl ftp]# rpm -ivh MySQL-client-5.5.29-2.rhel5.i386.rpm

Preparing...                ########################################### [100%]
   1:MySQL-client           ########################################### [100%]

4.安装完成以后启动mysql
[root@hxl subsys]# service mysql start
Starting MySQL...The server quit without updating PID file [FAILED]b/mysql/hxl.pid).


发现数据库无法启动,查看错误日志/var/lib/mysql/hxl.err,发现错误如下:
130130 22:30:32 [ERROR] Fatal error: Can't open and lock privilege tables: Table 'mysql.host' doesn't exist

解决办法执行如下命令
#mysql_install_db --user=mysql

5.启动数据库
[root@hxl mysql]# service mysql start
Starting MySQL....                                         [  OK  ]

6.登录数据库
[root@hxl mysql]# mysql -h hxl -uroot
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.5.29 MySQL Community Server (GPL)

Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved.

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>
mysql>
mysql>
mysql> select version();
+-----------+
| version() |
+-----------+
| 5.5.29    |
+-----------+
1 row in set (0.00 sec)

注:如果没有安装mysql client,就不会有mysql,mysqladmin等命令。

或者用如下命令登录mysql:

#mysql -u root -p
   Enter password: (输入密码)
   其中-u后跟的是用户名,-p要求输入密码,回车后在输入密码处输入密码。

注意:这个mysql文件在/usr/bin目录下,与后面讲的启动文件/etc/init.d/mysql不是一个文件。

在安装mysql5.6的时候,安装包随机给root用户生成了一个密码,该密码在'/root/mysql_secret'文件里。

当使用mysql -u root -p [password]登录后,需要使用如下命令更改密码:

mysql> SET PASSWORD=PASSWORD('123456');

如果不执行set password,就执行其他命令,就会碰到如下错误:

ERROR 1820 (HY000): You must SET PASSWORD before executing this statement 

7.生成my.cnf文件

默认情况下mysql是不会生成my.cnf文件的,但可以进入到/usr/share/mysql/目录找一个cnf文件生成my.cnf文件,如下:

cp /usr/share/mysql/my-huge.cnf /etc/my.cnf

然后编辑my.cnf,按照需要修改或添加相应参数.

其他参考资料:

http://baifeng520999.blog.163.com/blog/static/3379464320077881212180/

http://blog.youkuaiyun.com/zyc_reg/article/details/6570214

http://blog.youkuaiyun.com/cxin917/article/details/9148515

注:红色部分为安装MySQL-server-5.6.16-1.linux_glibc2.5.x86_64.rpm碰到的不同原文的问题。

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值