本文针对mysql-noinstall版本,也就是解压缩版的安装配置应用做了个总结,这些操作都是平时很常用的操作。文章中不对mysql的可执行文 件安装版做介绍了,可执行安装版有很多的弊端,我也不一一说了。总之,我喜欢绿色环保的,包括eclipse、tomcat、jboss、apache也 是,即使操作系统重装了,这些软件也不需要重装,可谓一劳永逸!
环境:
Windows 7
mysql-5.5.22-win32.zip
一、下载MySQL
我的下载地址:http://ftp.jaist.ac.jp/pub/mysql/Downloads/MySQL-5.5/mysql-5.5.22-win32.zip
(你可以去官网下最新版本的)
二、安装过程
1、解压缩mysql-5.5.22-win32.zip到一个目录,例如我自己的是D:\mysql-5.5.22-win32。
2、在mysql-5.1.62 目录下新建一个my.ini,拷贝my-large.ini代码至my.ini;修改后如下(中文说明为添加部分):
- # Example MySQL config file for large systems.
- #
- # This is for a large system with memory = 512M where the system runs mainly
- # MySQL.
- #
- # MySQL programs look for option files in a set of
- # locations which depend on the deployment platform.
- # You can copy this option file to one of those
- # locations. For information about these locations, see:
- # http://dev.mysql.com/doc/mysql/en/option-files.html
- #
- # In this file, you can use all long options that a program supports.
- # If you want to know which options a program supports, run the program
- # with the "--help" option.
- # The following options will be passed to all MySQL clients
- [client]
- #password = ling
- port = 3306
- socket = /tmp/mysql.sock
- #设置客户端字符集
- default-character-set=utf8
- # Here follows entries for some specific programs
- # The MySQL server
- [mysqld]
- port = 3306
- socket = MySQL
- skip-external-locking
- key_buffer_size = 256M
- max_allowed_packet = 1M
- table_open_cache = 256
- sort_buffer_size = 1M
- read_buffer_size = 1M
- read_rnd_buffer_size = 4M
- myisam_sort_buffer_size = 64M
- thread_cache_size = 8
- query_cache_size= 16M
- # Try number of CPU's*2 for thread_concurrency
- thread_concurrency = 8
- #这里是我们修改的内容
- basedir=D:\\mysql-5.5.22-win32
- # 设置mysql数据库的数据的存放目录,必须是data,或者是\\xxx\data
- datadir=D:\\mysql-5.5.22-win32\\data
- # 设置mysql服务器的字符集
- default-character-set=utf8
- #Server=L:/mysql-noinstall-5.1.62-win32/bin/mysqld-nt.exe
- # Don't listen on a TCP/IP port at all. This can be a security enhancement,
- # if all processes that need to connect to mysqld run on the same host.
- # All interaction with mysqld must be made via Unix sockets or named pipes.
- # Note that using this option without enabling named pipes on Windows
- # (via the "enable-named-pipe" option) will render mysqld useless!
- #
- #skip-networking
- # Replication Master Server (default)
- # binary logging is required for replication
- log-bin=mysql-bin
- # binary logging format - mixed recommended
- binlog_format=mixed
- # required unique id between 1 and 2^32 - 1
- # defaults to 1 if master-host is not set
- # but will not function as a master if omitted
- server-id = 1
- # Replication Slave (comment out master section to use this)
- #
- # To configure this host as a replication slave, you can choose between
- # two methods :
- #
- # 1) Use the CHANGE MASTER TO command (fully described in our manual) -
- # the syntax is:
- #
- # CHANGE MASTER TO MASTER_HOST=<host>, MASTER_PORT=<port>,
- # MASTER_USER=<user>, MASTER_PASSWORD=<password> ;
- #
- # where you replace <host>, <user>, <password> by quoted strings and
- # <port> by the master's port number (3306 by default).
- #
- # Example:
- #
- # CHANGE MASTER TO MASTER_HOST='125.564.12.1', MASTER_PORT=3306,
- # MASTER_USER='joe', MASTER_PASSWORD='secret';
- #
- # OR
- #
- # 2) Set the variables below. However, in case you choose this method, then
- # start replication for the first time (even unsuccessfully, for example
- # if you mistyped the password in master-password and the slave fails to
- # connect), the slave will create a master.info file, and any later
- # change in this file to the variables' values below will be ignored and
- # overridden by the content of the master.info file, unless you shutdown
- # the slave server, delete master.info and restart the slaver server.
- # For that reason, you may want to leave the lines below untouched
- # (commented) and instead use CHANGE MASTER TO (see above)
- #
- # required unique id between 2 and 2^32 - 1
- # (and different from the master)
- # defaults to 2 if master-host is set
- # but will not function as a slave if omitted
- #server-id = 2
- #
- # The replication master for this slave - required
- #master-host = <hostname>
- #
- # The username the slave will use for authentication when connecting
- # to the master - required
- #master-user = <username>
- #
- # The password the slave will authenticate with when connecting to
- # the master - required
- #master-password = <password>
- #
- # The port the master is listening on.
- # optional - defaults to 3306
- #master-port = <port>
- #
- # binary logging - not required for slaves, but recommended
- #log-bin=mysql-bin
- # Uncomment the following if you are using InnoDB tables
- #innodb_data_home_dir = C:\\mysql\\data\\
- #innodb_data_file_path = ibdata1:10M:autoextend
- #innodb_log_group_home_dir = C:\\mysql\\data\\
- # You can set .._buffer_pool_size up to 50 - 80 %
- # of RAM but beware of setting memory usage too high
- #innodb_buffer_pool_size = 256M
- #innodb_additional_mem_pool_size = 20M
- # Set .._log_file_size to 25 % of buffer pool size
- #innodb_log_file_size = 64M
- #innodb_log_buffer_size = 8M
- #innodb_flush_log_at_trx_commit = 1
- #innodb_lock_wait_timeout = 50
- [mysqldump]
- quick
- max_allowed_packet = 16M
- [mysql]
- no-auto-rehash
- # Remove the next comment character if you are not familiar with SQL
- #safe-updates
- [myisamchk]
- key_buffer_size = 128M
- sort_buffer_size = 128M
- read_buffer = 2M
- write_buffer = 2M
- [mysqlhotcopy]
- interactive-timeout
3、给系统path环境变量添加:D:\mysql-5.5.22-win32\bin
然后编写启动脚本startup.bat,放在D:\mysql-5.5.22-win32\bin路径下,此启动脚本会将mysql5注册到系统服务中: @echo off echo start mysql5 on localhost mysqld --install mysql5 --defaults-file=D:\mysql-5.5.22-win32\my.ini net start mysql5 pause
停止脚本stop.bat放在D:\mysql-5.5.22-win32\bin路径下,停止脚本会将系统服务中MySQL5卸载掉: @echo off echo stop mysql5 net stop mysql5 mysqld --remove mysql5 pause
6、配置完毕后,右键以管理员身份运行D:\mysql-5.5.22-win32\bin路径下的startup.bat批处理文件,在系统服务中有一个mysql5的服务,并且已经启动,然后测试下数据库的安装情况,
在dos窗口下,进入D:\>cd D:\mysql-5.5.22-win32\bin路径下,输入mysqlshow,即可显示数据库信息,
示例如下: Microsoft Windows XP [版本 5.1.2600] (C) 版权所有 1985-2001 Microsoft Corp.
C:\Documents and Settings\guoy>d:
D:\>cd D:\mysql-5.5.22-win32\bin
D:\mysql-5.5.22-win32\bin>mysqlshow
+--------------------+
| Databases |
+--------------------+
| information_schema |
| test |
+--------------------+
D:\mysql-5.5.22-win32\bin>
如上信息说明数据库安装成功还有其他测试命令:
mysqlshow -u root mysql
mysqladmin -u root version status proc
//===========================================================================//
免安装版本,访问MySQL时常会出现:access denied for user 'root'@'localhost' using password yes
出现这种情况多是root密码没有设置或错误,解决办法如下:
1. 管理员登陆系统,停止 MySQL 服务或者结束 MySQL 进程。
2. 启动 WINDOWS 的命令行窗口(即通常的 DOS 窗口),切换到你的 “MySQL\bin” 目录下。
例如我的是 “D:\SERVER\MySQL5122\bin”,然后执行下面的粗体的命令:
(注意你的 “my.ini” 位置)
Microsoft Windows XP [版本 5.1.2600]
(C) 版权所有 1985-2001 Microsoft Corp.
C:\Documents and Settings\MMC>d:
D:\>cd D:\SERVER\MySQL5122\bin
D:\SERVER\MySQL5122\bin>mysqld --defaults-file="D:\SERVER\MySQL5122\my.ini" --console --skip-grant-tables
090801 4:43:54 InnoDB: Started; log sequence number 0 585546
090801 4:43:54 [ERROR] Can't open and lock privilege tables: Table 'mysql.servers' doesn't exist
090801 4:43:54 [Note] mysqld: ready for connections.
Version: '5.1.22-rc-community' socket: '' port: 3306 MySQL Community Server (GPL)
_
可能会出现一些警告信息和错误,但只要出现下面信息,就说明 MySQL 已经起来了。
Version: '5.1.22-rc-community' socket: '' port: 3306 MySQL Community Server (GPL)
3. 不关闭此命令行窗口,重新打开一个命令行窗口,同样切到 “mysql\bin” 目录下,然后执行下面的粗体的命令:
Microsoft Windows XP [版本 5.1.2600]
(C) 版权所有 1985-2001 Microsoft Corp.
C:\Documents and Settings\MMC>d:
D:\>cd D:\SERVER\MySQL5122\bin
D:\SERVER\MySQL5122\bin>mysql -u root mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.1.22-rc-community MySQL Community Server (GPL)
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql>
到这步,我想任何一个使用 MySQL 的人都知道后面要做什么了!(^a^)
mysql>
mysql> UPDATE user SET Password=PASSWORD('mynewpass') where USER='root';
Query OK, 2 rows affected (0.05 sec)
Rows matched: 2 Changed: 2 Warnings: 0
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.02 sec)
mysql> quit
Bye
4. 好了到此步,可以关闭第一个 DOS 窗口了。打开系统服务控制窗口(控制面板--管理工具--服务),启动 MySQL 服务。
5. 在剩下的第二个 DOS 窗口中,用新的 ROOT 密码连接 MySQL。
D:\SERVER\MySQL5122\bin>mysql -u root -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 MySQL Community Server (GPL)
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql> quit
Bye
至此,系统恢复 ROOT 用户管理权限完成。
//====================================================================//
对于安装版MYSQL完全卸载方法
第一次安装mysql输入密码后,如果你想卸载重装,便会出现要求输入原来设定的密码,否则安装不成功。遇到这样的问题,是你没有完全卸载mysql数据库。
MysqlQ完全卸载方法:
1.清除MYSQL的安装目录,默认是C:Program Files
2.清除MYSQL数据存放目录,一般在C:programData目录下(win7)或者C:Documents and SettingsAll Users.windowsApplication Data(XP)目录下删除MySQL文件夹。
(需要注意的时Application Data这个文件夹默认是隐藏的,要通过 工具->文件夹选项->查看->显示所有文件与文件夹来设置隐藏文件可见)。
3.这步很重要,之前不管我怎么卸载MYSQL清空残余文件都还是要输入原始密码,后来试试找了***册表,清空后果然有效。
删除注册表数据,通过regedit,删除以下几个文件:
HKEY_LOCAL_MACHINE/SYSTEM/ControlSet001/Services/Eventlog/Applications/MySQL
HKEY_LOCAL_MACHINE/SYSTEM/ControlSet002/Services/Eventlog/Applications/MySQL
HKEY_LOCAL_MACHINE/SYSTEM/CurrentControlSet/Services/Eventlog/Applications/MySQL
至此Mysql数据库便完全卸载了,然后重新安装即可。
Windows下mysql忘记root密码的解决方法
Mysql版本:5.1.55-community MySQL Community Server (GPL)
1、 首先检查mysql服务是否启动,若已启动则先将其停止服务,可在开始菜单的运行,使用命令:
net stop mysql
或者在windows任务管理器中结束mysqld.exe进程,或者在控制面板,管理工具里面的服务找到mysql,将其停止服务。
打开第一个cmd窗口,切换到mysql的bin目录,运行命令:
mysqld --defaults-file="C:Program FilesMySQLMySQL Server 5.1my.ini" --console --skip-grant-tables
注释:
该命令通过跳过权限安全检查,开启mysql服务,这样连接mysql时,可以不用输入用户密码。
"C:Program FilesMySQLMySQL Server 5.1my.ini"指配置文件my.ini,一般在mysql安装目录里面。
如:
===============================================================================
C:Program FilesMySQLMySQL Server 5.1bin>mysqld --defaults-file="C:Program FilesMySQLMySQL Server 5.1my.ini" --console --skip-grant-tables
110301 9:20:07 [Warning] '--default-character-set' is deprecated and will be removed in a future release. Please use '--character-set-server' instead.
110301 9:20:07 [Note] Plugin 'FEDERATED' is disabled.
110301 9:20:07 InnoDB: Initializing buffer pool, size = 46.0M
110301 9:20:07 InnoDB: Completed initialization of buffer pool
110301 9:20:07 InnoDB: Started; log sequence number 0 44233
110301 9:20:07 [Note] mysqld: ready for connections.
Version: '5.1.55-community' socket: '' port: 3306 MySQL Community Server (GPL)
2、打开第二个cmd窗口,连接mysql:
输入命令:
mysql -uroot -p
出现:
Enter password:
在这里直接回车,不用输入密码。
然后就就会出现登录成功的信息,
如:
===============================================================================
Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 3
Server version: 5.1.55-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>
===============================================================================
使用命令:
show databases;
显示已有数据库:
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| test |
+--------------------+
3 rows in set (0.00 sec)
使用命令切换到mysql数据库:
use mysql;
使用命令更改root密码:
UPDATE user SET Password=PASSWORD('newpassword') where USER='root';
刷新权限:
FLUSH PRIVILEGES;
然后退出,重新登录:
quit
重新登录:
mysql -uroot -p
出现输入密码提示,输入新的密码即可登录:
Enter password: ***********
显示登录信息:
Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 9
Server version: 5.1.55-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>
到这里root密码就已经修改成功了,用Ctrl+C将第一个cmd窗口结束,那样就会停止mysql服务,如:
=============================================================================== C:Program FilesMySQLMySQL Server 5.1bin>mysqld --defaults-file="C:Program F
ilesMySQLMySQL Server 5.1my.ini" --console --skip-grant-tables
110301 10:29:47 [Warning] '--default-character-set' is deprecated and will be re
moved in a future release. Please use '--character-set-server' instead.
110301 10:29:47 [Note] Plugin 'FEDERATED' is disabled.
110301 10:29:47 InnoDB: Initializing buffer pool, size = 46.0M
110301 10:29:47 InnoDB: Completed initialization of buffer pool
110301 10:29:48 InnoDB: Started; log sequence number 0 44233
110301 10:29:48 [Note] mysqld: ready for connections.
Version: '5.1.55-community' socket: '' port: 3306 MySQL Community Server (GPL)
(此处输入ctrl+c)
110301 10:30:58 [Note] mysqld: Normal shutdown
110301 10:30:58 InnoDB: Starting shutdown...
110301 10:31:03 InnoDB: Shutdown completed; log sequence number 0 44233
110301 10:31:03 [Note] mysqld: Shutdown complete
Mysql服务停止了,输入命令:
net start mysql,即可重新启动mysql服务,如:
===============================================================================
C:Program FilesMySQLMySQL Server 5.1bin>net start mysql
MySQL 服务正在启动 .
MySQL 服务已经启动成功。
C:Program FilesMySQLMySQL Server 5.1bin>
可以参考:http://www.cnblogs.com/firstdream/archive/2012/04/06/2434894.html
图解安装步骤: http://hi.baidu.com/houwenbin1986/blog/item/affbb70eef75abe7ab64578a.html