linux下卸载和安装mysql数据库的方法

本文详细介绍了在Linux环境下MySQL 5.1版本的下载、安装、老版本卸载、登录设置及权限配置过程。从下载指定版本的MySQL到确保安装后的正常使用,包括设置root用户密码和远程访问权限。

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

1.1  MySQL下载

下载地址:http://www.mysql.com/downloads/mysql/5.5.html#downloads

版本:5.1.68

平台:linux general

Generic Linux (glibc 2.3) (x86, 64-bit), RPM Package 
版本:MySQL Server

(MySQL-server-5.1.68-1.glibc23.x86_64.rpm)

注:这个不是最新版,但却是我之前使用的版本,考虑兼容性,使用该版本。

1.2  检查老版本并卸载

1、查找以前是否装有mysql

命令:rpm -qa|grep -i mysql

可以看到mysql的两个包:

mysql-4.1.12-3.RHEL4.1

mysqlclient10-3.23.58-4.RHEL4.1

2、删除mysql

删除命令:rpm -e --nodeps 包名

( rpm -ev mysql-4.1.12-3.RHEL4.1 )

3、删除老版本mysql的开发头文件和库

命令:rm -fr /usr/lib/mysql

rm -fr /usr/include/mysql

注意:卸载后/var/lib/mysql中的数据及/etc/my.cnf不会删除,如果确定没用后就手工删除

rm -f /etc/my.cnf

rm -fr /var/lib/mysql

1.3  安装

[root@localhost soft]# rpm -ivh MySQL-server-5.1.68-1.glibc23.x86_64.rpm 

Preparing...                ########################################### [100%]

   1:MySQL-server           ########################################### [100%]

PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !

To do so, start the server, then issue the following commands:

/usr/bin/mysqladmin -u root password 'new-password'

/usr/bin/mysqladmin -u root -h localhost.localdomain password 'new-password'

Alternatively you can run:

/usr/bin/mysql_secure_installation

which will also give you the option of removing the test

databases and anonymous user created by default.  This is

strongly recommended for production servers.

See the manual for more instructions.

Please report any problems with the /usr/bin/mysqlbug script!

Starting MySQL. SUCCESS! 

[root@localhost soft]# mysql

-bash: /bin/mysql: 没有那个文件或目录

1.4  登录MySQL

命令是mysql, mysql 的使用语法如下:  
mysql [-u username] [-h host] [-p[password]] [dbname]  
username 与 password 分别是 MySQL 的用户名与密码,mysql的初始管理帐号是root,没有密码,注意:这个root用户不是Linux的系统用户。MySQL默认用户是root,由于初始没有密码,第一次进时只需键入mysql即可。 

MySQL默认没有密码,安装完毕增加密码的重要性是不言而喻的。

1、命令

usr/bin/mysqladmin -u root password 'new-password'

 格式:mysqladmin -u用户名 -p旧密码 password 新密码

2、例子

 例1:给root加个密码123456。

 键入以下命令 :

[root@test1 local]# /usr/bin/mysqladmin -u root password 123456

 注:因为开始时root没有密码,所以-p旧密码一项就可以省略了。

3、测试是否修改成功

1)不用密码登录

[root@test1 local]# mysql

ERROR 1045: Access denied for user: 'root@localhost' (Using password: NO)

 显示错误,说明密码已经修改。

2)用修改后的密码登录

[root@test1 local]# mysql -u root -p 

1.5  最后赋予访问权限(很重要,不然客户端连接不上)

GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;

给来自任何IP地址的用户user分配可对所有数据库的所有表进行所有操作的权限限,并设定口令为'123456'。

 

转载于:https://www.cnblogs.com/lzw121/p/4450308.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值