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

mysql远程连数据之经验总结(蛇年博客第一问,来自上海大雪的亲切问候)

1. 新增用户

mysql>insert into mysql.user(Host,User,Password) values("localhost","lionbule",password("hello1234"));
mysql>flush privileges;
2. 修改用户密码

mysql>update mysql.user set password=password('new password') where User="lionbule" and Host="localhost";
mysql>flush privileges;

3. 删除用户

mysql>DELETE FROM user WHERE User="lionbule" and Host="localhost";
mysql>flush privileges;

4. 权限分配

    4.1. grant用法

           grant 权限 on 数据库.* to 用户名@'登录主机' identified by '密码'

权限:  
    常用总结, ALL/ALTER/CREATE/DROP/SELECT/UPDATE/DELETE  
数据库:  
     *.*                    表示所有库的所有表  
     test.*                表示test库的所有表  
     test.test_table  表示test库的test_table表       
用户名:  
     mysql账户名  
登陆主机:  
     允许登陆mysql server的客户端ip  
     '%'表示所有ip  
     'localhost' 表示本机  
     '192.168.10.2' 特定IP  
密码:  
      账户对应的登陆密码  
举例如下:


mysql>grant all  on test.* to lionbule@'%' identified by 'hello1234';
mysql>flush privileges;

php测试一番


<?php
mysql_connect("192.168.1.101", "root", "") or die("Could not connect: " . mysql_error());
?>


D:\xampp\mysql\bin\mysql -h192.192.192.230 -uuserTest -p;
Enter password: ********
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 11
Server version: 5.5.25a MySQL Community Server (GPL)


Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.


Oracle is a registered trademark of Oracle Corporation and