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

1.1  MySQL下载

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

版本:5.1.68node

平台:linux generalmysql

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

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

注:这个不是最新版,但倒是我以前使用的版本,考虑兼容性,使用该版本。数据库

1.2  检查老版本并卸载

一、查找之前是否装有mysqlbash

命令:rpm -qa|grep -i mysqldom

能够看到mysql的两个包:测试

mysql-4.1.12-3.RHEL4.1加密

mysqlclient10-3.23.58-4.RHEL4.1

二、删除mysql

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

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

三、删除老版本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默认没有密码,安装完毕增长密码的重要性是不言而喻的。

一、命令

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

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

二、例子

 例1:给root加个密码123456。

 键入如下命令 :

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

 注:由于开始时root没有密码,因此-p旧密码一项就能够省略了。

三、测试是否修改为功

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'。

相关文章
相关标签/搜索