MySQL service added to Windows system service

 

Original link: http://xhc66.iteye.com/blog/1389095

 

MySQL installation configuration (win7 64-bit)

turn, organize.

MySQL version is

mysql-noinstall-5.1.66-winx64.zip (no installation version)

mysql-workbench-gpl-5.2.44-win32.msi

mysql-connector-java-5.1.22

The mysql configuration database encoding is utf-8 (specified in my.ini).

1 Installation

First extract mysql-noinstall-5.1.66-winx64.zip to d:\appspace\mysql

Move the data folder to d:/appspace/mysqlData, that is, the data path of mysql is: d:/appspace/mysqlData/data

The my.ini configuration file has 2 selectable locations:

Open E:\appSpace\mysql \ my-large.ini (if mysql fails to start with 1067 error later, try using my-huge.ini or others), add the following lines at the end, and save as my. ini(C:\Windows).

 #--------------------------------------------------------

[mysqld]

basedir=d:/appspace/mysql

datadir=d:/appspace/mysqlData/data

default-character-set=utf8

[WinMySQLAdmin]

Server=d:/appspace/mysql/bin/mysqld.exe

#default-character-set=utf8

[client]

default-character-set=utf8

#--------------------------------------------------------

 

You can view the set character set in mysql (be sure to set utf-8 in [mysqld]):

mysql> show variables like 'character%';

+--------------------------+-----------------------------------+

| Variable_name            | Value                             |

+--------------------------+-----------------------------------+

| character_set_client     | utf8                              |

| character_set_connection | utf8                              |

| character_set_database   | utf8                              |

| character_set_filesystem | binary                            |

| character_set_results    | utf8                              |

| character_set_server     | utf8                              |

| character_set_system     | utf8                              |

| character_sets_dir       | d:\appspace\mysql\share\charsets\ |

+--------------------------+-----------------------------------+

 

2 Configure the service (the command line must be run as administrator)

1) Add MySQL to the service.

Enter cmd in Windows Run, then there is a prompt (cmd.exe) above, right-click cmd.exe, select Run as administrator, enter the path: d:/appspace/mysql /bin>

输入  mysqld --install MySQL --defaults-file="C:\Windows\my.ini"

To specify defaults-file.

Enter services.msc in the command line and press Enter, you can see that MySQL has been added to Services,

The content in Path to executable is 

d:\appspace\mysql\bin\mysqld --defaults-file=C:\windows\my.ini MySQL

2) Start MySQL

Click the Start button in MySQL Service, or type net start mysql in the command line (Run as administrator).

If there is a 1067 error and cannot start, recheck the my.ini file (described earlier)

3) Close MySQL

Click the Stop button in MySQL Service, or type net stop mysql in the command line (Run as administrator).

4) Delete the mysql service

mysqld –remove

 

3 Environment variables

Add d:\appspace\mysql\bin to Path.

 

4 Operation

Login to the database:

C:\Users\zhang10>mysql -u root -p

Enter password: *** (the initial value of the password can be set to root or empty)

 

After entering mysql, the command ends with a semicolon.

 

Show all database schemas:

mysql> show databases;

 

Create a new database schema and specify the encoding utf-8, otherwise garbled characters will appear.

create database md11uft8 character set utf8;

 

Check this database md11utf8:

mysql> use md11utf8;

 

Create a table:

mysql> create table basicinfo (id int primary key auto_increment, name varchar(30) not null, age int not null);

 

插入数据:

mysql> insert into basicinfo(id, name, age) values('1','张三','30');

mysql> insert into basicinfo(id, name, age) values('3','李四','25');

 

查询:

mysql> select * from basicinfo;

+----+------+-----+

| id | name | age |

+----+------+-----+

|  1 |      |  30 |

|  3 |      |  25 |

+----+------+-----+

 

可看到name中的值没有显示(中文显示不了)。

在MySQL workbench中插入值,查询会正确显示。

但是在命令行中查询显示乱码(DOS不支持UTF8从MYSQL中显示),解决如下:

mysql> set names gbk;

 

修改root的密码:

mysql>use mysql;

mysql>update user set Password=password('newpassword') where User='root';

mysql>flush privileges;

另外MySQL的学习网站:

http://dev.mysql.com/doc/refman/5.1/zh/tutorial.html#entering-queries 

 

 

MySQL Workbench:

先启动Mysql:在命令行(Run as administrator)中输入 net start mysql.

MySQL的安装配置(win7 64-bit)

转,整理。

MySQL 版本是

mysql-noinstall-5.1.66-winx64.zip(免安装版)

mysql-workbench-gpl-5.2.44-win32.msi

mysql-connector-java-5.1.22

mysql 配置数据库编码为utf-8(my.ini中指定).

1 安装

先将mysql-noinstall-5.1.66-winx64.zip解压缩到 d:\appspace\mysql

将其中的data 文件夹移动到d:/appspace/mysqlData 即mysql的 data路径为:d:/appspace/mysqlData/data

my.ini配置文件有2个可选择的位置:

打开E:\appSpace\mysql \ my-large.ini (如果后面mysql出现1067错误,启动不了的话,可试着用my-huge.ini或其他), 在最后加上如下几行,然后另存为my.ini(C:\Windows).

 #--------------------------------------------------------

[mysqld]

basedir=d:/appspace/mysql

datadir=d:/appspace/mysqlData/data

default-character-set=utf8

[WinMySQLAdmin]

Server=d:/appspace/mysql/bin/mysqld.exe

#default-character-set=utf8

[client]

default-character-set=utf8

#--------------------------------------------------------

 

可以在mysql中查看设定的字符集(一定要在[mysqld] 中设定utf-8):

mysql> show variables like 'character%';

+--------------------------+-----------------------------------+

| Variable_name            | Value                             |

+--------------------------+-----------------------------------+

| character_set_client     | utf8                              |

| character_set_connection | utf8                              |

| character_set_database   | utf8                              |

| character_set_filesystem | binary                            |

| character_set_results    | utf8                              |

| character_set_server     | utf8                              |

| character_set_system     | utf8                              |

| character_sets_dir       | d:\appspace\mysql\share\charsets\ |

+--------------------------+-----------------------------------+

 

2  配置服务(命令行必须以administrator身份运行)

1)将MySQL 添加到服务中。

在Windows Run中输入cmd,这时上面有提示(cmd.exe),右键单击cmd.exe, 选择Run as administrator,进入路径: d:/appspace/mysql /bin>

输入  mysqld --install MySQL --defaults-file="C:\Windows\my.ini"

要指定defaults-file.

命令行中输入services.msc回车,可以看到MySQL已被添加到Services中,

Path to executable中的内容为 

d:\appspace\mysql\bin\mysqld --defaults-file=C:\windows\my.ini MySQL

2)启动MySQL

在MySQL Service中点击Start按钮,或者在命令行(Run as administrator)中输入 net start mysql.

如果出现1067错误,启动不了,则重新检查my.ini文件(前面有描述)

3)关闭MySQL

在MySQL Service中点击Stop按钮,或者在命令行(Run as administrator)中输入 net stop mysql.

4)删除mysql服务

mysqld –remove

 

3 环境变量

将d:\appspace\ mysql\bin添加到Path中。

 

4 操作

登录数据库:

C:\Users\zhang10>mysql -u root -p

Enter password: ***  (密码初始值可设置为root或者为空)

 

进入mysql后,命令后以分号结尾。

 

显示所有的数据库模式:

mysql> show databases;

 

新建一个数据库模式,指定编码utf-8,否则会出现乱码。

create database md11uft8 character set utf8;

 

选中此数据库md11utf8:

mysql> use md11utf8;

 

创建一个表:

mysql> create table basicinfo (id int primary key auto_increment, name varchar(30) not null, age int not null);

 

插入数据:

mysql> insert into basicinfo(id, name, age) values('1','张三','30');

mysql> insert into basicinfo(id, name, age) values('3','李四','25');

 

查询:

mysql> select * from basicinfo;

+----+------+-----+

| id | name | age |

+----+------+-----+

|  1 |      |  30 |

|  3 |      |  25 |

+----+------+-----+

 

可看到name中的值没有显示(中文显示不了)。

在MySQL workbench中插入值,查询会正确显示。

但是在命令行中查询显示乱码(DOS不支持UTF8从MYSQL中显示),解决如下:

mysql> set names gbk;

 

修改root的密码:

mysql>use mysql;

mysql>update user set Password=password('newpassword') where User='root';

mysql>flush privileges;

另外MySQL的学习网站:

http://dev.mysql.com/doc/refman/5.1/zh/tutorial.html#entering-queries 

 

 

MySQL Workbench:

先启动Mysql:在命令行(Run as administrator)中输入 net start mysql.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326853515&siteId=291194637