window下面安装mysql配置

时间:2021-11-24 17:05:52

一、下载 mysql-noinstall-5.1.34-win32.zip(http://www.mysql.com/downloads/mysql/4.0.html

二、配置MySQL的参数

1、解压缩绿色版软件到c:\mysql-5.1.34

设置系统环境变量
MYSQL_HOME=c:\mysql-5.1.34

在Path中添加 %MYSQL_HOME%\bin;

2、修改C:\mysql-5.1.34\my-small.ini文件内容,添加红色内容

[client]
#password = your_password
port = 3306
socket = /tmp/mysql.sock
default-character-set=gbk

[mysqld]
port = 3306
socket = /tmp/mysql.sock
default-character-set=gbk
skip-locking
key_buffer = 16K
max_allowed_packet = 1M
table_cache = 4
sort_buffer_size = 64K
read_buffer_size = 256K
read_rnd_buffer_size = 256K
net_buffer_length = 2K
thread_stack = 64K

将修改后的文件另存为my.ini

3、安装MySQL的服务,服务名自己定义为MySQL.
1)、进入DOS窗口,或在DOS窗口下进入E:\Program Files\mysql-5.1.32目录
2)、执行安装MySQL服务名的命令:
mysqld --install MySQL --defaults-file="C:\mysql-5.1.34\my.ini"

Service successfully installed.

3)、启动MySQL服务
net start mysql
MySQL服务正在启动 .
MySQL服务无法启动。

4)、登陆MySQL服务器
mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.1.32-community MySQL Community Edition (GPL)

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql>

注意:MySQL的管理员用户名为root,密码默认为空。

5)、查看数据库
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| test |
+--------------------+
3 rows in set (0.02 sec)

可以看到MySQL服务器中有三个数据库。

6)、使用数据库
mysql> use test
Database changed

7)、查看数据库中的表
mysql> show tables;
Empty set (0.00 sec)

8)、创建表ttt
mysql> create table ttt(a int,b varchar(20));
Query OK, 0 rows affected (0.00 sec)

9)、插入三条数据
mysql> insert into ttt values(1,'aaa');
Query OK, 1 row affected (0.02 sec)

mysql> insert into ttt values(2,'bbb');
Query OK, 1 row affected (0.00 sec)

mysql> insert into ttt values(3,'ccc');
Query OK, 1 row affected (0.00 sec)

10)、查询数据
mysql> select * from ttt;
+------+------+
| a | b |
+------+------+
| 1 | aaa |
| 2 | bbb |
| 3 | ccc |
+------+------+
3 rows in set (0.00 sec)

11)、删除数据
mysql> delete from ttt where a=3;
Query OK, 1 row affected (0.01 sec)

删除后查询操作结果:
mysql> select * from ttt;
+------+------+
| a | b |
+------+------+
| 1 | aaa |
| 2 | bbb |
+------+------+
2 rows in set (0.00 sec)

12)、更新数据
mysql> update ttt set b = 'xxx' where a =2;
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0

查看更新结果:
mysql> select * from ttt;
+------+------+
| a | b |
+------+------+
| 1 | aaa |
| 2 | xxx |
+------+------+
2 rows in set (0.00 sec)

13)、删除表
mysql> drop table ttt;
Query OK, 0 rows affected (0.00 sec)

查看数据库中剩余的表:
mysql> show tables;
Empty set (0.00 sec)


三、更改MySQL数据库root用户的密码

1、使用mysql数据库
mysql> use mysql
Database changed

2、查看mysql数据库中所有的表
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)

3、删除mysql数据库中用户表的所有数据
mysql> delete from user;
Query OK, 3 rows affected (0.00 sec)

4、创建一个root用户,密码为“xiaohui”。
mysql>grant all on *.* to root@'%' identified by 'xiaohui' with grant option;
Query OK, 0 rows affected (0.02 sec)

5、查看user表中的用户
mysql> select User from user;
+------+
| User |
+------+
| root |
+------+
1 row in set (0.00 sec)

6、重启MySQL:更改了MySQL用户后,需要重启MySQL服务器才可以生效。
net stop mysql
MySQL 服务正在停止..
MySQL 服务已成功停止。

net start mysql
MySQL 服务正在启动 .
MySQL 服务已经启动成功。

7、重新登陆MySQL服务器
mysql -uroot -pxiaohui
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.1.32-community MySQL Community Edition (GPL)

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql>

四、数据库的创建与删除

1、创建数据库testdb
mysql> create database testdb;
Query OK, 1 row affected (0.02 sec)

2、使用数据库testdb
mysql> use testdb;
Database changed

3、删除数据库testdb
mysql> drop database testdb;
Query OK, 0 rows affected (0.00 sec)

4、退出登陆
mysql>exit
Bye

C:\Documents and Settings\Administrator>

五、操作数据库数据的一般步骤

1、启动MySQL服务器
2、登陆数据库服务器
3、使用某个要操作的数据库
4、操作该数据库中的表,可执行增删改查各种操作。
5、退出登陆。

改密码:use mysql; update user set Password=PASSWORD('229141383root') where User='root';

远程拒绝访问解决方法:

C:\>mysql -uroot -p
Enter password: ******
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.1.22-rc-community-log MySQL Community Server (GPL)

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> grant all privileges on *.* to 'tlbb'@'127.0.0.1' identified by 'xiaoli1h';
Query OK, 0 rows affected (0.05 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.06 sec)

mysql> exit