Chinaunix首页 | 论坛 | 博客
  • 博客访问: 364950
  • 博文数量: 83
  • 博客积分: 5322
  • 博客等级: 中校
  • 技术积分: 1057
  • 用 户 组: 普通用户
  • 注册时间: 2010-04-11 11:27
个人简介

爱生活,爱阅读

文章分类

全部博文(83)

文章存档

2015年(1)

2013年(1)

2012年(80)

2011年(1)

分类: LINUX

2012-01-15 19:53:54

   计划在一台vmware fedora(环境A)上建立mysql客户端,另一个vmware fedora 环境(环境B)上搭建mysql-server,这样环境A可以访问环境B mysql数据库,同时进行linux下数据库程序开发验证,这里简要记录安装过程。
1、在环境B上直接尝试登陆mysql数据库
------------------------------------------------------------------------------------
[root@localhost ~]# mysql -uroot -p -hlocalhost
Enter password:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
------------------------------------------------------------------------------------
查询本地环境是否安装对应的软件包:
[root@localhost ~]# rpm -qa | grep mysql-server
[root@localhost ~]#
尚未安装
直接通过yum安装:
------------------------------------------------------------------------------------
[root@localhost admin]#
[root@localhost admin]# yum install mysql-server
Loading "installonlyn" plugin
Setting up Install Process
Parsing package install arguments
Resolving Dependencies
--> Running transaction check
---> Package mysql-server.i386 0:5.0.45-6.fc7 set to be updated
--> Processing Dependency: perl(DBI) for package: mysql-server
--> Processing Dependency: perl-DBI for package: mysql-server
--> Processing Dependency: mysql = 5.0.45-6.fc7 for package: mysql-server
--> Processing Dependency: perl-DBD-MySQL for package: mysql-server
--> Restarting Dependency Resolution with new changes.
--> Running transaction check
---> Package mysql.i386 0:5.0.45-6.fc7 set to be updated
---> Package perl-DBI.i386 0:1.53-2.fc7 set to be updated
---> Package perl-DBD-MySQL.i386 0:3.0008-1.fc7 set to be updated
--> Processing Dependency: mysql-libs = 5.0.45-6.fc7 for package: mysql
--> Restarting Dependency Resolution with new changes.
--> Running transaction check
---> Package mysql-libs.i386 0:5.0.45-6.fc7 set to be updated
Dependencies Resolved
=============================================================================
 Package                 Arch       Version          Repository        Size
=============================================================================
Installing:
 mysql-server            i386       5.0.45-6.fc7     updates           9.8 M
Installing for dependencies:
 mysql                   i386       5.0.45-6.fc7     updates           2.7 M
 perl-DBD-MySQL          i386       3.0008-1.fc7     fedora            148 k
 perl-DBI                i386       1.53-2.fc7       fedora            611 k
Updating for dependencies:
 mysql-libs              i386       5.0.45-6.fc7     updates           1.5 M
Transaction Summary
=============================================================================
Install      4 Package(s)        
Update       1 Package(s)        
Remove       0 Package(s)        
Total download size: 15 M
Is this ok [y/N]: y
Downloading Packages:
(1/4): mysql-libs-5.0.45- 100% |=========================| 1.5 MB    01:13    
(2/4): mysql-server-5.0.4 100% |=========================| 9.8 MB    06:07    
(3/4): perl-DBD-MySQL-3.0 100% |=========================| 148 kB    00:03    
(4/4): mysql-5.0.45-6.fc7 100% |=========================| 2.7 MB    01:50    
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
  Updating  : mysql-libs                   ######################### [1/6]
  Installing: perl-DBI                     ######################### [2/6]
  Installing: mysql                        ######################### [3/6]
  Installing: perl-DBD-MySQL               ######################### [4/6]
  Installing: mysql-server                 ######################### [5/6]
  Cleanup   : mysql-libs                   ######################### [6/6]
Installed: mysql-server.i386 0:5.0.45-6.fc7
Dependency Installed: mysql.i386 0:5.0.45-6.fc7 perl-DBD-MySQL.i386 0:3.0008-1.fc7 perl-DBI.i386 0:1.53-2.fc7
Dependency Updated: mysql-libs.i386 0:5.0.45-6.fc7
Complete!
[root@localhost admin]#
安装之后继续登陆,发现还是一样的提示
查服务是否启动:
[root@localhost ~]# service mysqld status
没有启动,
启动守护进程服务:
[root@localhost ~]# service mysqld restart
2、服务启动后登陆
------------------------------------------------------------------------------------
[root@localhost ~]#mysql -uroot -proot -hlocalhost
mysql ERROR 1045: Access denied for user: (Using password: YES)
------------------------------------------------------------------------------------
后来发现时默认安装的mysql-server root用户密码为空,上面所用密码错误导致的
尝试如下登陆:
[root@localhost ~]#mysql -uroot -p -hlocalhost
OK,登陆成功
修改root登陆密码方法如下:
 
3、在环境A上登陆环境B上的mysql数据库
------------------------------------------------------------------------------------
[root@localhost ~]# mysql -uroot -p -h192.168.62.129
Enter password:
ERROR 1130 (00000): Host '192.168.62.128' is not allowed to connect to this MySQL server
[root@localhost ~]#
------------------------------------------------------------------------------------
这是因为mysql指定了某个账户只能由某个服务器登陆,可以通过在环境B上进行下面非配置解决:
3.1、修改root账户,只有192.168.62.128登陆root,则在环境B登陆mysql,进行如下配置:
------------------------------------------------------------------------------------
[root@localhost ~]# mysql -uroot -p -hlocalhost
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.0.45 Source distribution
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| test               |
+--------------------+
3 rows in set (0.00 sec)
mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> show tables;
+---------------------------+
| Tables_in_mysql           |
+---------------------------+
| columns_priv              |
| db                        |
| func                      |
| help_category             |
| help_keyword              |
| help_relation             |
| help_topic                |
| host                      |
| proc                      |
| procs_priv                |
| tables_priv               |
| time_zone                 |
| time_zone_leap_second     |
| time_zone_name            |
| time_zone_transition      |
| time_zone_transition_type |
| user                      |
+---------------------------+
17 rows in set (0.00 sec)
mysql> update user set host='%' where user='root';
ERROR 1062 (23000): Duplicate entry '%-root' for key 1
mysql> describe user;
+-----------------------+-----------------------------------+------+-----+---------+-------+
| Field                 | Type                              | Null | Key | Default | Extra |
+-----------------------+-----------------------------------+------+-----+---------+-------+
| Host                  | char(60)                          | NO   | PRI |         |       |
| User                  | char(16)                          | NO   | PRI |         |       |
| Password              | char(41)                          | NO   |     |         |       |
| Select_priv           | enum('N','Y')                     | NO   |     | N       |       |
| Insert_priv           | enum('N','Y')                     | NO   |     | N       |       |
| Update_priv           | enum('N','Y')                     | NO   |     | N       |       |
| Delete_priv           | enum('N','Y')                     | NO   |     | N       |       |
| Create_priv           | enum('N','Y')                     | NO   |     | N       |       |
| Drop_priv             | enum('N','Y')                     | NO   |     | N       |       |
| Reload_priv           | enum('N','Y')                     | NO   |     | N       |       |
| Shutdown_priv         | enum('N','Y')                     | NO   |     | N       |       |
| Process_priv          | enum('N','Y')                     | NO   |     | N       |       |
| File_priv             | enum('N','Y')                     | NO   |     | N       |       |
| Grant_priv            | enum('N','Y')                     | NO   |     | N       |       |
| References_priv       | enum('N','Y')                     | NO   |     | N       |       |
| Index_priv            | enum('N','Y')                     | NO   |     | N       |       |
| Alter_priv            | enum('N','Y')                     | NO   |     | N       |       |
| Show_db_priv          | enum('N','Y')                     | NO   |     | N       |       |
| Super_priv            | enum('N','Y')                     | NO   |     | N       |       |
| Create_tmp_table_priv | enum('N','Y')                     | NO   |     | N       |       |
| Lock_tables_priv      | enum('N','Y')                     | NO   |     | N       |       |
| Execute_priv          | enum('N','Y')                     | NO   |     | N       |       |
| Repl_slave_priv       | enum('N','Y')                     | NO   |     | N       |       |
| Repl_client_priv      | enum('N','Y')                     | NO   |     | N       |       |
| Create_view_priv      | enum('N','Y')                     | NO   |     | N       |       |
| Show_view_priv        | enum('N','Y')                     | NO   |     | N       |       |
| Create_routine_priv   | enum('N','Y')                     | NO   |     | N       |       |
| Alter_routine_priv    | enum('N','Y')                     | NO   |     | N       |       |
| Create_user_priv      | enum('N','Y')                     | NO   |     | N       |       |
| ssl_type              | enum('','ANY','X509','SPECIFIED') | NO   |     |         |       |
| ssl_cipher            | blob                              | NO   |     |         |       |
| x509_issuer           | blob                              | NO   |     |         |       |
| x509_subject          | blob                              | NO   |     |         |       |
| max_questions         | int(11) unsigned                  | NO   |     | 0       |       |
| max_updates           | int(11) unsigned                  | NO   |     | 0       |       |
| max_connections       | int(11) unsigned                  | NO   |     | 0       |       |
| max_user_connections  | int(11) unsigned                  | NO   |     | 0       |       |
+-----------------------+-----------------------------------+------+-----+---------+-------+
37 rows in set (0.12 sec)
------------------------------------------------------------------------------------
mysql>use mysql;
mysql>update user set host='192.168.62.128' where user='root';
mysql>flush privileges;
------------------------------------------------------------------------------------
3.2、修改root账户,任意用户登陆root,则在环境B登陆mysql,进行如下配置:
------------------------------------------------------------------------------------
mysql>use mysql;
mysql>update user set host='%' where user='root';
mysql>flush privileges;
------------------------------------------------------------------------------------
3.3、通过grant配置登陆权限
---------------------------------------------------------------------------------------------
命令格式:
grant 权限1,权限2,…,权限n on 数据库名称.表名称 to 用户名@用户地址 identified by ‘连接口令’;
权限包括:create,drop,insert,update,select,reload,delete,references,shutdown,
grant,index,alter,process等。
----------------------------------------------------------------------------------------------
命令:mysql>grant all privileges on test.* to identified by ‘roottoor′;
mysql>flush privileges;
|------------------------------------------------------------------------------------
目的:设定用户root分配可对数据库test所有表进行所有的操作权限,同时设定口令为roottoor。

---------------------------------------------------------------------------------------------
命令:mysql>grant select,insert,update on test.* to   identified by
′123456′;
mysql>flush privileges;
|--------------------------------------------
目的:设定192.168.62.128用户moo分配可对数据库test所有表进行select,insert,update等操作权限,同时设定口令为123456。
至此,可以在环境A的环境上进行登陆环境B的mysql server了。
|-----------------------------------------设置之前--------------------------------------------
[root@localhost ~]#
[root@localhost ~]# mysql -uroot -p -h192.168.62.129
Enter password:
ERROR 1130 (00000): Host '192.168.62.128' is not allowed to connect to this MySQL server
[root@localhost ~]#
|----------------------------------------设置之后--------------------------------------------
在环境A上:
[root@localhost ~]# ifconfig
eth0      Link encap:Ethernet  HWaddr 00:0C:29:E5:66:83 
          inet addr:192.168.62.128  Bcast:192.168.62.255  Mask:255.255.255.0
          inet6 addr: fe80::20c:29ff:fee5:6683/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:20755 errors:0 dropped:0 overruns:0 frame:0
          TX packets:17391 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:11540148 (11.0 MiB)  TX bytes:3097607 (2.9 MiB)
          Interrupt:18 Base address:0x2024
lo        Link encap:Local Loopback 
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:10167 errors:0 dropped:0 overruns:0 frame:0
          TX packets:10167 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:90759697 (86.5 MiB)  TX bytes:90759697 (86.5 MiB)
[root@localhost ~]#
[root@localhost ~]# mysql -uroot -p -h192.168.62.129
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 5.0.45 Source distribution
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql>
-------------------------------------------END--------------------------------------------
 
阅读(1299) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~