Linux的MySQL安装方法

1、查看是否有安装没卸载的版本  rpm -qa|grep -i MySQL


2、如果有强制卸载:rpm -e --nodeps   版本名称


3、开始安装MySQL服务端 :    rpm -ivh   MySQL-server-5.5.39-2.linux2.6.i386.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 zjeasy15 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 at http://bugs.mysql.com/






4、查看server端是否安装成功:rpm -qa | grep MySQL
                       显示:MySQL-client-5.5.39-2.linux2.6.i386


5、开始安装MySQL客户端 :    rpm -ivh   MySQL-client-5.5.39-2.linux2.6.i386.rpm
 
显示以下信息,说明安装成功:
 Preparing...                ########################################### [100%]
   1:MySQL-client           ########################################### [100%]


6、查看client端是否安装成功:rpm -qa | grep MySQL
                       显示: MySQL-client-5.5.39-2.linux2.6.i386
                               MySQL-server-5.5.39-2.linux2.6.i386


7、启动MySQL:/etc/init.d/mysql start 


8、输入: mysql


9、--注意这里,因为MySQL默认没有密码,所以这里我们没有输入密码就直接连上了。
 
--修改密码,这个是安装Server 中提示的:
[root@rac2 ~]# /usr/bin/mysqladmin -u root password root
[root@rac2 ~]# mysql
ERROR 1045 (28000): Access denied for user'root'@'localhost' (using password: NO)
--修改密码之后,就提示要使用密码了。
 
[root@rac2 ~]# mysql -u root -p
Enter password:


Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.5.15 MySQL CommunityServer (GPL)




2.3.3 查看MySQL端口 3306, 这个是默认端口:
[root@rac2 ~]# netstat -nat|grep 3306
tcp       0      0 192.168.3.100:32842         192.168.3.100:3306          TIME_WAIT  
tcp       0      0 :::3306                     :::*                        LISTEN     
 
10、设置开机自启动
--查看MySQL 开机自启动设置:
[root@rac2 ~]# chkconfig --list |grep mysql
mysql           0:off   1:off  2:on    3:on    4:on   5:on    6:off
这里的数字分别代表Linux启动的不同模式,3是命令行,5是窗口。
 
11、关闭开机自启动
[root@rac2 ~]# chkconfig mysql off
[root@rac2 ~]# chkconfig --list |grep mysql
mysql          0:off   1:off  2:off   3:off   4:off  5:off   6:off
 
12、启用开机自启动:
[root@rac2 ~]# chkconfig mysql on
[root@rac2 ~]# chkconfig --list |grep mysql
mysql           0:off   1:off  2:on    3:on    4:on   5:on    6:off
[root@rac2 ~]#
 
13、将Mysql 从chkconfig服务里删除:
[root@rac2 ~]# chkconfig --del mysql
[root@rac2 ~]# chkconfig --list |grep mysql
 
14、将Mysql 添加到chkconfig里:
[root@rac2 ~]# chkconfig --add mysql      
[root@rac2 ~]# chkconfig --list |grep mysql
mysql           0:off   1:off  2:on    3:on    4:on   5:on    6:off






15、出现这个问题:1130 -host 'localhost' is not allowed to connect to this mysql server


  需要更改远程其他主机访问权限,方法如下:


1。 改表法。
可能是你的帐号不允许从远程登陆,只能在localhost。这个时候只要在localhost的那台电脑,登入mysql后,更改 "mysql" 数据库里的 "user" 表里的 "host" 项,从"localhost"改称"%"
mysql -u root -pvmwaremysql>use mysql;
mysql>update user set host = '%' where user = 'root';
mysql>select host, user from user;
2. 授权法。
例如,你想myuser使用mypassword从任何主机连接到mysql服务器的话。
GRANT ALL PRIVILEGES ON *.* TO 'myuser'@'%' IDENTIFIED BY 'mypassword' WITH GRANT OPTION;
FLUSH PRIVILEGES;
如果你想允许用户myuser从ip为192.168.1.6的主机连接到mysql服务器,并使用mypassword作为密码
GRANT ALL PRIVILEGES ON *.* TO 'myuser'@'192.168.1.3' IDENTIFIED BY 'mypassword' WITH GRANT OPTION;
FLUSH PRIVILEGES;
如果你想允许用户myuser从ip为192.168.1.6的主机连接到mysql服务器的dk数据库,并使用mypassword作为密码
GRANT ALL PRIVILEGES ON dk.* TO 'myuser'@'192.168.1.3' IDENTIFIED BY 'mypassword' WITH GRANT OPTION;
FLUSH PRIVILEGES;
我用的第一个方法,刚开始发现不行,在网上查了一下,少执行一个语句 mysql>FLUSH RIVILEGES 使修改生效.就可以了
另外一种方法,不过我没有亲自试过的,在csdn.net上找的,可以看一下.
在安装mysql的机器上运行:
1、d:\mysql\bin\>mysql -h localhost -u root //这样应该可以进入MySQL服务器
2、mysql>GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION //赋予任何主机访问数据的权限
3、mysql>FLUSH PRIVILEGES //修改生效
4、mysql>EXIT //退出MySQL服务器
这样就可以在其它任何的主机上以root身份登录啦!
追问
一开始是好好的,就是因为想设置远程访问,按照这个网址的介绍http://www.studyday.net/2010/08/64
 
机器重启后,结果本地的mysql也进不去了,没有办法修改表。
回答
确认你的mysql是否启动成功,
可以用 下面的方法试下
 
1、d:\mysql\bin\>mysql -h localhost -u root //这样应该可以进入MySQL服务器
2、mysql>GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION //赋予任何主机访问数据的权限
3、mysql>FLUSH PRIVILEGES //修改生效
4、mysql>EXIT //退出MySQL服务器


grant all privileges on *.* to 'myroot'@'192.168.0.213' identified by  'myroot' with grant option;  
flush   privileges;


delete from user where user='192.168.0.217';
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值