mysql windows 安装与使用

来源:互联网 发布:js中select标签 编辑:程序博客网 时间:2024/05/17 07:57

mysql windows 安装与使用

 (2010-09-12 23:53:07)
转载
标签: 

杂谈

分类: JavaEE

[安装]

下载地址: http://www.mysql.com/downloads/mysql 下载和运行 mysql-essential-5.1.50-win32.msi

 

(本例中不把其设置为 windows  服务)

缺省情况下,程序文件安装在 C:\Program Files\MySQL\MySQL Server 5.1,

数据库文件安装在 C:\Documents and Settings\All Users\Application Data\MySQL\MySQL Server 5.1\data

文件 C:\Program Files\MySQL\MySQL Server 5.1\my.ini 记录了相关的配置信息。

 

C:\Documents and Settings\All Users\Application Data\MySQL\MySQL Server 5.1\data 目录显示,目前安装了两个database: mysql 和 test

 

[启动与停止]

启动数据库: 运行cmd ,

C\> C:\Program Files\MySQL\MySQL Server 5.1\bin\mysqld --console

 

停止数据库: 运行cmd,

C\> C:\Program Files\MySQL\MySQL Server 5.0\bin\mysqladmin -u root shutdown

mysql 缺省的根用户是 root 他的缺省密码是 空。

如果用户设置了root密码,则上面命令是:

C:\Program Files\MySQL\MySQL Server 5.1\bin\mysqladmin -u root -p shutdown

 

把 mysql 设置成 windows 的服务:

必须先用上面命令停掉数据库,然后运行:

C\> C:\Program Files\MySQL\MySQL Server 5.1\bin\mysqld --install

数据库会随着每次电脑开机自动运行,而不需在运行数据库启动命令。

 

[测试mysql]

注意,目前的缺省用户是所谓的“匿名”用户,'@'localhost

C:\Program Files\MySQL\MySQL Server 5.1\bin>mysqlshow
+--------------------+
    Databases      |
+--------------------+
| information_schema |
| test               |
+--------------------+

用 root 用户查看, root 用户缺省密码是空。

C:\Program Files\MySQL\MySQL Server 5.1\bin>mysqlshow -u root 

 

+--------------------+
    Databases      |
+--------------------+
| information_schema |
| mysql              |
| test               |
+--------------------+


 

显示mysql数据库:

C:\Program Files\MySQL\MySQL Server 5.1\bin>mysqlshow mysql
mysqlshow: Access denied for user ''@'localhost' to database 'mysql'

 

必须用 root 账户

C:\Program Files\MySQL\MySQL Server 5.1\bin>mysqlshow -u root mysql
Database: mysql
+---------------------------+
         Tables           |
+---------------------------+
| columns_priv              |
| db                        |
| event                     |
| func                      |
| general_log               |
| help_category             |
| help_keyword              |
| help_relation             |
| help_topic                |
| host                      |
| ndb_binlog_index          |
| plugin                    |
| proc                      |
| procs_priv                |
| servers                   |
| slow_log                  |
| tables_priv               |
| time_zone                 |
| time_zone_leap_second     |
| time_zone_name            |
| time_zone_transition      |
| time_zone_transition_type |
| user                      |
+---------------------------+

 

显示 test 数据库:

C:\Program Files\MySQL\MySQL Server 5.1\bin>mysqlshow test
Database: test
+--------+
| Tables |
+--------+
+--------+

 

没表!

 

查询 数据库 mysql 中 db 表,并显示其 Host, Db, User 字段。

C:\Program Files\MySQL\MySQL Server 5.1\bin>mysql -u root -e "SELECT Host,Db,Use
r FROM db" mysql
+------+---------+------+
| Host | Db      | User |
+------+---------+------+
| %    | test    |      |
| %    | test\_% |      |
+------+---------+------+

 

可见,mysql 是个“元”数据库,用于管理其他数据库。

 

[修改密码匿名密码]

C:\Program Files\MySQL\MySQL Server 5.1\bin>mysql -u rootWelcome to the MySQL monitor.  Commands end with ; or \g.Your MySQL connection id is 8Server version: 5.1.50-community MySQL Community Server (GPL)
Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.This software comes with ABSOLUTELY NO WARRANTY. This is free software,and you are welcome to modify and redistribute it under the GPL v2 license
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> SET PASSWORD FOR ''@'localhost' = PASSWORD('localhost');Query OK, 0 rows affected (0.06 sec)
查看当前用户列表:
mysql> select Host,user from mysql.user;+-----------+------+| Host      | user |+-----------+------+| 127.0.0.1 | root || localhost |      || localhost | root |+-----------+------+3 rows in set (0.00 sec)
user 为空的一项即位匿名用户,
删除匿名用户:
mysql> delete from mysql.user where user ='';Query OK, 1 row affected (0.28 sec)
mysql> select Host,user from mysql.user;+-----------+------+| Host      | user |+-----------+------+| 127.0.0.1 | root || localhost | root |+-----------+------+2 rows in set (0.00 sec)
为 root 指定密码:
C:\Program Files\MySQL\MySQL Server 5.1\bin>mysqladmin -u root password "root"
如果 root 秘密忘记了,如何复位:
* 停止运行mysql
* 编辑文件(任意名), 如:c:\a.txt,内容:
SET PASSWORD FOR 'root'@'localhost' = PASSWORD('MyNewPassword');
* 运行:
C:\> C:\mysql\bin\mysqld --init-file=C:\a.txt
即新的 root 密码生效。
[数据库转移到另一台机器]
 
 
0 0
原创粉丝点击