日期:2014-05-16  浏览次数:20878 次

mysql在linux下的安装(转)

原文链接:http://bluedest.iteye.com/blog/469621

1.先查看是否已经安装过mysql
rpm -qa|grep My
如果显示如下:
[root@localhost ~]# rpm -qa|grep My
MySQL-server-community-5.0.83-0.rhel5
MySQL-client-community-5.0.83-0.rhel5

则先把上述两项卸载
rpm -e --nodeps MySQL-client-community-5.0.83-0.rhel5
rpm -e --nodeps MySQL-server-community-5.0.83-0.rhel5


2.下载MySQL的安装文件
安装MySQL需要下面两个文件:
MySQL-server-5.0.9-0.i386.rpm 
MySQL-client-5.0.9-0.i386.rpm
下载地址为:http://dev.mysql.com/downloads/mysql/5.0.html,
打开此网页,下拉网页找到“Linux x86 RPM downloads”项,找到“Server”和“Client programs”项,下载需要的上述两个rpm文件。


3.安装服务端
rpm -ivh MySQL-server-5.0.9-0.i386.rpm

4.装完后
执行/etc/init.d/mysql start 启动服务
然后:
[root@test1 local]# netstat -nat
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address   Foreign Address  State 
tcp  0  0 0.0.0.0:3306  0.0.0.0:*   LISTEN 
上面显示可以看出MySQL服务已经启动。


5.安装客户端
运行如下命令:
[root@test1 local]# rpm -ivh MySQL-client-5.0.9-0.i386.rpm
warning: MySQL-client-5.0.9-0.i386.rpm: V3 DSA signature: NOKEY, key ID 5072e1f5
Preparing...    ########################################### [100%]
1:MySQL-client  ########################################### [100%]
显示安装完毕。

6.登录MySQL
登录MySQL的命令是mysql, mysql 的使用语法如下:
mysql [-u username] [-h host] [-p[password]] [dbname]
username 与 password 分别是 MySQL 的用户名与密码,mysql的初始管理帐号是root,没有密码,注意:这个root用户不是Linux的系统用户。MySQL默认用户是root,由于初始没有密码,第一次进时只需键入mysql即可。
[root@test1 local]# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.


7.创建新用户
grant all privileges on *.* to test@'%' identified by 'test';
grant all privileges on *.* to test@'localhost' identified by 'test';
这个语句创建了一个test用户,密码是test,可以在任何ip上登录此mysql的任意数据库