linux - yum 安装配置mysql可以远程连接

YUM查看可用安装包

[plain]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. [root@microlmj ~]# yum list mysql*  

[plain]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. Available Packages  
  2. MySQL-python.x86_64                       1.2.3-0.3.c1.1.el6                base                                      
  3. mysql.x86_64                              5.1.73-3.el6_5                    updates                                   
  4. mysql-bench.x86_64                        5.1.73-3.el6_5                    updates                                   
  5. mysql-connector-java.noarch               1:5.1.17-6.el6                    base                                      
  6. mysql-connector-odbc.x86_64               5.1.5r1144-7.el6                  base                                      
  7. mysql-devel.x86_64                        5.1.73-3.el6_5                    updates                                   
  8. mysql-embedded.x86_64                     5.1.73-3.el6_5                    updates                                   
  9. mysql-embedded-devel.x86_64               5.1.73-3.el6_5                    updates                                   
  10. mysql-libs.x86_64                         5.1.73-3.el6_5                    updates                                   
  11. mysql-server.x86_64                       5.1.73-3.el6_5                    updates                                   
  12. mysql-test.x86_64                         5.1.73-3.el6_5                    updates    

安装mysql,mysql-server,mysql-devel.

[plain]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. [root@microlmj~]# yum -y install mysql  
[plain]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. [root@microlmj~]# yum -y install mysql-server  
[plain]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. [root@microlmj~]# yum -y install mysql-devel  
---Complete!
设置字符编码

[plain]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. [root@microlmj~]# vi /etc/my.cnf   
  2. [mysqld]  
  3. datadir=/var/lib/mysql  
  4. socket=/var/lib/mysql/mysql.sock  
  5. user=mysql  
  6. # Disabling symbolic-links is recommended to prevent assorted security risks  
  7. symbolic-links=0  
  8.   
  9. [mysqld_safe]  
  10. log-error=/var/log/mysqld.log  
  11. pid-file=/var/run/mysqld/mysqld.pid  
  12.   
  13. #new add  
  14. default-character-set=utf8  

启动服务

[plain]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. [root@microlmj init.d]# /etc/rc.d/init.d/mysqld start  
  2.                                                            [  OK  ]  
  3. Starting mysqld:                                           [  OK  ]  
刚安装的mysql root 用户 是没有密码的 登录 自己设置密码

[plain]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. [root@microlmj init.d]# mysql -u root  
  2. Welcome to the MySQL monitor.  Commands end with ; or \g.  
  3. Your MySQL connection id is 2  
  4. Server version: 5.1.73 Source distribution  
  5.   
  6. Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.  
  7.   
  8. Oracle is a registered trademark of Oracle Corporation and/or its  
  9. affiliates. Other names may be trademarks of their respective  
  10. owners.  
  11.   
  12. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.  
  13.   
  14. mysql>   
看一下用户列表
[plain]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. mysql> select user ,host, password from mysql.user;  
  2. +------+-----------------------+----------+  
  3. | user | host                  | password |  
  4. +------+-----------------------+----------+  
  5. | root | localhost             |          |  
  6. | root | ay14031710421034561bz |          |  
  7. | root | 127.0.0.1             |          |  
  8. |      | localhost             |          |  
  9. |      | ay14031710421034561bz |          |  
  10. +------+-----------------------+----------+  
  11. 5 rows in set (0.00 sec)  
密码栏都是空的
给root@localhost设置一个密码

[plain]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. mysql> set password for root@localhost=password('yourpassword');  
  2. Query OK, 0 rows affected (0.00 sec)  
再看一下用户表
[plain]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. mysql> select user ,host, password from mysql.user;  
  2. +------+-----------------------+-------------------------------------------+  
  3. | user | host                  | password                                  |  
  4. +------+-----------------------+-------------------------------------------+  
  5. | root | localhost             | *7E7C3D7567802A1EC617020149BB4B81E551B5EB |  
  6. | root | ay14031710421034561bz |                                           |  
  7. | root | 127.0.0.1             |                                           |  
  8. |      | localhost             |                                           |  
  9. |      | ay14031710421034561bz |                                           |  
  10. +------+-----------------------+-------------------------------------------+  
  11. 5 rows in set (0.00 sec)  
退出再重新登录

[plain]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. mysql> exit  
  2. Bye  
  3. [root@microlmj init.d]# mysql -u root   
  4. ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)  
需要密码了 -.-
输入密码登录 0>.<0
[plain]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. [root@microlmj init.d]# mysql -u root -p  
  2. Enter password:   
  3. Welcome to the MySQL monitor.  Commands end with ; or \g.  
  4. Your MySQL connection id is 7  
  5. Server version: 5.1.73 Source distribution  
  6. ...  
  7. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.  
  8.   
  9. mysql>   
本地的访问就没问题了 perhaps  -.-
但是俺想远程访问
新建个用户microlmj  (*用root账户登陆先)
[plain]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. mysql> insert into mysql.user(Host,User,Password) values("%","microlmj",password("microlmj"));  
Host字段是 % 允许所有地址访问
刷新系统权限-.-

[plain]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. mysql> flush privileges;  
  2. Query OK, 0 rows affected (0.00 sec)  
[plain]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. [root@microlmj init.d]# mysql -u microlmj -p  
  2. Enter password:   
  3. Welcome to the MySQL monitor.  Commands end with ; or \g.  
  4. ...  
  5. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.  
  6.   
  7. mysql>  
用新建的用户登录 创建一个表试试

[plain]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. mysql> use test;  
  2. Database changed  
  3. mysql> show tables;  
  4. Empty set (0.00 sec)  
  5.   
  6. mysql> create table user (id int primary key, name varchar(10));  
  7. Query OK, 0 rows affected (0.01 sec)  
  8.   
  9. mysql> desc user;  
  10. +-------+-------------+------+-----+---------+-------+  
  11. | Field | Type        | Null | Key | Default | Extra |  
  12. +-------+-------------+------+-----+---------+-------+  
  13. | id    | int(11)     | NO   | PRI | NULL    |       |  
  14. | name  | varchar(10) | YES  |     | NULL    |       |  
  15. +-------+-------------+------+-----+---------+-------+  
  16. 2 rows in set (0.00 sec)  
好吧,用navicat测试一下远程访问行不行 -.-


连接成功 -.-
Complete!
-.-

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值