安装过程是引用网上前辈的文章,但是我在安装过程中遇到一个小的问题。
安装MYSQL是出现"终结点映射器中没有更多的终结点可用"
在安装MySQL的某一步中勾选了“Add firewall exception for this port”,但是服务器的Windows的防火墙又没有开启,所以会有这个提示,一般情况下点击OK,不会产生什么系统错误。
windows下MySQL更改数据库文件目录及1045,1067错误
如果以前安装过,没有全部工作目录删除,就会出现ERROR 1045错误
这时需要:
1、将全部安装目录删除
2、默认数据目录:#datadir="C:/Documents and Settings/All Users/Application Data/MySQL/MySQL Server 5.5/data"
删除C:/Documents and Settings/All Users/Application Data/下的mysql目录
3、重新安装,就不会出现1045错误
如果需要修改默认数据目录,可能出现1067错误
这是需要:
1、默认数据目录:#datadir="C:/Documents and Settings/All Users/Application Data/MySQL/MySQL Server 5.5/data"
如果我要改变目录为 datadir="C:/MySQL/appData/"
需要将C:/Documents and Settings/All Users/Application Data/MySQL/MySQL Server 5.5/data目录下的全部文件复制到新的目录下
2、这时,重新启动,就不会出现1067错误了
原网址:http://blog.sina.com.cn/s/blog_6aff6bb9010103r6.html
-----------------------------------------------------------------------------------------------------------------------------------------
Windows平台下安装与配置MySQL 详细安装与配置
目录
Windows平台下安装与配置MySQL
1、Window系统下安装MySQL介绍
在Windows操作系统下,有两种MySQL图形化安装包,分别为Windows Essentials 和Windows MSI Installer。前者包含了MySQL中最主要和最常用的功能,但是不包含一些不常用的功能,后者包含了MySQL全部功能,包括不常用的功能。
如果安装MySQL数据库是为了学习和软件开发,安装Windows Essentials安装包已经足够了。
2、安装MySQL
我在下面使用的版本是mysql-5.5.21-win32.msi(Windows Essentials安装包)。
具体安装过程如下:
(1)、双击mysql-5.5.21-win32.msi安装文件,弹出安装欢迎界面
(2)、单击Next按钮,进入选择安装类型的界面,安装类型有三种分别是Typical(典型)、
Complete(完全)和Custom(自定义).
l Typical:这种只安装常用的组件,默认安装路径是C:\Program Files\MySQL\MySQL Server5.1。默认情况是安装这种方式。
l Complete:这种安装所有组件,占用的磁盘空间也比较大,一般不推荐这种方式安装
l Custom:用户可以自由选择需要安装的组件、选择安装路径等。下面将选择这种安装方式。
(3)、选择Custom选项,进入自定义安装界面
自定义安装界面出现了MySQL Server和Client Programs的内容等。这分别表示安装MySQL的服务器端的组件和客户端的组件。单击Browse按钮,可以改变MySQL的安装路径,我把它安装在D盘。
单击红叉处会出现下拉菜单,下拉菜单的各选项介绍如下:
选项1:表示这个附加属性安装到本地的硬盘上。
选项2:表示这个附加属性及其子特性安装到本地的硬盘上。
选项3:表示当需要时才安装这个附加特性。
选项4:表示不安装这个附加特性。
(4)、单击Next
(5)、单击Install,进入MySQL安装界面,安装过程中,通过进度条来显示安装的进度。安装完成后会提示是否进行服务器的配置。
3、配置MySQL
(1)、点击finish按钮并进入MySQl服务器配置界面。
有两种配置类型:
l Detailed Configuration 将详细配置用户的连接数,字符编码等问题
l Standard Configuraion 将按照MySQL最常用的配置进行配置
为了了解MySQL的详细配置过程,在这里选择Detailed Configuration进行配置
(2)点击Next,进入选择服务器类型的界面
选择服务器类型有三种,分别是
l Developer Machine(开发者类型):只占用很少的资源,消耗的内存资源最少。主要适用于软件开发的用户,下面也将选择这类服务器类型。
l Server Machine(服务器类型):占用的资源稍多一些,主要用于做服务器的机器,可以选择该项。
l Dedicate MySQL Server Machine(专用数据库服务器):占用所有的可用资源,消耗内存最大,用于专用的数据库服务器。
(3)、点击next,进入选择数据库用途的界面
也有三种用途类型:
l 第一种:多功能数据库,支持所有数据库的操作
l 第二种:主要用于进行事务处理
l 第三种:主要用于非事务性的处理
下面将选择第一种数据库用途选择。
(4)、单击next,进入设置InnoDB表空间的界面
设置表空间就是选择MySQL数据存放的位置,这个位置设好了,数据文件将存放在此处。
(5)、单击Next,进入设置服务器连接数。
有三个选项:
l 第一种:主要用于决策支持,该类型不需要很多的连接数,默认连接数为20个左右。
l 第二种:主要用于联机事务处理,默认连接数是500个。
l 第三种:可以手动设置连接数,选项的默认值是15个。
我在这里,选择第一种。
(6)、再单击Next进入设置网络和SQL Mode的界面。
l Enable TCP/IP Networking选项用来连接网络,在这里要打上勾
l PortNumber用来设置端口号,默认端口号是3306
l Add firewall exception for this port选项用来在防火墙上注册这个端口号,建议选择该选项。
l Enable Strict Mode选项用来设置SQL Mode为严格格式,这可以保证严格的检验输入的数据,可以控制MySQL的数据的安全性。
(7)、选择后的结果如上图选择,点击Next进入字符集配置的界面。
这个界面有三个选项
第一种:是默认字符集,支持英文和其他的西欧语言,默认值是Latin1。
第二种:能支持大部分语系的字符,默认值是utf-8.
第三种:手动设置字符集。
提示:如果需要使用中文,最好选择手动设置字符集,并将字符集设置为GBK或GB2312.
在这里,我选择了手动设置选择GBK.
(8)、然后单击Next按钮,进入设置Windows选项的界面
在Install As Windows Service选项下可以设置服务器名称,默认情况下为MySQL。
Launch the MySQL选项设置计算机开机自启动MySQL服务。
Include Bin Directory in Windows PATH选项将MySQL的应用程序的目录添加到系统的Path中,这样就可以在DOS窗口中访问MySQL,而不需要到MySQL的bin目录下进行访问。
(9)、选择好选项后,点击Next进入设置安全选择的界面
Modify Security Settings选项可以设置root用户的密码。
New root password表示为root用户设置密码
Confirm表示再此输入密码
Enable root access from remote machines选项用来设置能够从远程的机器使用root用户的权限登录。
Anonymous Account选项可以设置一个匿名用户,建议不要使用该选项。
(10)、选择好选项后,单击Next,进入准备执行的界面。
Prepare configuration 表示准备进行配置
Write configuration表示更新配置文件
Start service表示启动MySQL服务。
Apply security settings表示应用安全设置
四个阶段都执行完毕,将进入配置完成概念。
(11)点击Finish按钮,便完成了MySQL Server的配置。
4、启动MySQL服务并登陆MySQL数据库
(1)、如果要使用MySQL数据库,安装的时候却没有选择计算机开机自启动MySQL的选项的话,到路径:控制面板\所有控制面板项\管理工具,找到MySQL服务,并启动服务,
如果觉得麻烦的话,可以把该服务设置为开机自启动服务。
(2)、MySQL服务器启动后,便可登陆MySQL客户端打开cmd,输入主机IP和用户名,单击回车键后,进入输入密码界面,输入自己设置的密码
(3)登陆成功后,会出现“Welcome to the MySQL monitor“的欢迎语。
用户便可在这里通过输入命令开始数据库的操作了!
5、更改MySQL的设置
数据库安装好之后,可能会根据实际情况更改MySQL的某些设置,一般有两种方式来更改。
分别是:
l 通过配置向导来更改配置
l 手工来更改配置
配置向导安装比较简单,在这里我选择“手工更改配置“来解说如何更改配置,
用户可通过修改MySQL配置文件的方式来进行配置,这种配置方式更加灵活。
在进行手工配置之前,先要对MySQL文件有所了解,前面已经介绍过,MySQL的文件安装在D:\Program Files (x86)\MySQL\MySQL Server 5.5这个目录下。安装文件夹有4个文件夹分别是bin、include、lib和share
l bin文件下都是可执行文件
l include文件夹下都是头文件
l lib文件夹下都是库文件
l share文件夹下是字符集、语言等信息。
除了4个文件夹后,还有几个后缀名为.ini的文件,不同的.ini文件代表不同的意思,其中只有my.ini是正在使用的配置文件,所以更改配置也即是对该文件进行修改。
注意:更改完之后一定要重启服务器,这样更改后的配置才能起作用。
下面是my.ini的主要内容:
# MySQL Server Instance Configuration File
# ----------------------------------------------------------------------
# Generated by the MySQL Server Instance Configuration Wizard
#
#
# Installation Instructions
# ----------------------------------------------------------------------
#
# On Linux you can copy this file to /etc/my.cnf to set global options,
# mysql-data-dir/my.cnf to set server-specific options
# (@localstatedir@ for this installation) or to
# ~/.my.cnf to set user-specific options.
#
# On Windows you should keep this file in the installation directory
# of your server (e.g. C:\Program Files\MySQL\MySQL Server X.Y). To
# make sure the server reads the config file use the startup option
# "--defaults-file".
#
# To run run the server from the command line, execute this in a
# command line shell, e.g.
# mysqld --defaults-file="C:\Program Files\MySQL\MySQL Server X.Y\my.ini"
#
# To install the server as a Windows service manually, execute this in a
# command line shell, e.g.
# mysqld --install MySQLXY --defaults-file="C:\Program Files\MySQL\MySQL Server X.Y\my.ini"
#
# And then execute this in a command line shell to start the server, e.g.
# net start MySQLXY
#
#
# Guildlines for editing this file
# ----------------------------------------------------------------------
#
# In this file, you can use all long options that the program supports.
# If you want to know the options a program supports, start the program
# with the "--help" option.
#
# More detailed information about the individual options can also be
# found in the manual.
#
#
# CLIENT SECTION
# ----------------------------------------------------------------------
#
# The following options will be read by MySQL client applications.
# Note that only client applications shipped by MySQL are guaranteed
# to read this section. If you want your own MySQL client program to
# honor these values, you need to specify it as an option during the
# MySQL client library initialization.
#
[client] //客户端
port=3306 //端口
[mysql]
default-character-set=gbk //客户端默认字符编码
# SERVER SECTION
# ----------------------------------------------------------------------
#
# The following options will be read by the MySQL Server. Make sure that
# you have installed the server correctly (see above) so it reads this
# file.
#
[mysqld]
# The TCP/IP Port the MySQL Server will listen on
port=3306 //服务器端监听端口
#Path to installation directory. All paths are usually resolved relative to this.
basedir="D:/Program Files (x86)/MySQL/MySQL Server 5.5/" //MySQL的安装路径
#Path to the database root
datadir="D:/ProgramFiles(x86)/MySQL/MySQL Server 5.5/Data/" //创建的数据库数据文件的存放路径
# The default character set that will be used when a new schema or table is
# created and no character set is defined
character-set-server=gbk //服务器端字符编码
# The default storage engine that will be used when create new tables when
default-storage-engine=INNODB //默认的存储引擎
# Set the SQL mode to strict
sql-mode="STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"
# The maximum amount of concurrent sessions the MySQL server will
# allow. One of these connections will be reserved for a user with
# SUPER privileges to allow the administrator to login even if the
# connection limit has been reached.
max_connections=100 //数据库最大连接数
# Query cache is used to cache SELECT results and later return them
# without actual executing the same query once again. Having the query
# cache enabled may result in significant speed improvements, if your
# have a lot of identical queries and rarely changing tables. See the
# "Qcache_lowmem_prunes" status variable to check if the current value
# is high enough for your load.
# Note: In case your tables change very often or if your queries are
# textually different every time, the query cache may result in a
# slowdown instead of a performance improvement.
query_cache_size=0 //查询时缓冲的大小
# The number of open tables for all threads. Increasing this value
# increases the number of file descriptors that mysqld requires.
# Therefore you have to make sure to set the amount of open files
# allowed to at least 4096 in the variable "open-files-limit" in
# section [mysqld_safe]
table_cache=256 //表示所有进程打开表的总数
# Maximum size for internal (in-memory) temporary tables. If a table
# grows larger than this value, it is automatically converted to disk
# based table This limitation is for a single table. There can be many
# of them.
tmp_table_size=34M //内存中临时表的最大值
# How many threads we should keep in a cache for reuse. When a client
# disconnects, the client's threads are put in the cache if there aren't
# more than thread_cache_size threads from before. This greatly reduces
# the amount of thread creations needed if you have a lot of new
# connections. (Normally this doesn't give a notable performance
# improvement if you have a good thread implementation.)
thread_cache_size=8 //保留客服端线程的缓存
#*** MyISAM Specific options
# The maximum size of the temporary file MySQL is allowed to use while
# recreating the index (during REPAIR, ALTER TABLE or LOAD DATA INFILE.
# If the file-size would be bigger than this, the index will be created
# through the key cache (which is slower).
myisam_max_sort_file_size=100G //表示MySQL重建索引时所允许的最大临时文件的大小
# If the temporary file used for fast index creation would be bigger
# than using the key cache by the amount specified here, then prefer the
# key cache method. This is mainly used to force long character keys in
# large tables to use the slower key cache method to create the index.
myisam_sort_buffer_size=68M //表示重建索引时缓存的大小
# Size of the Key Buffer, used to cache index blocks for MyISAM tables.
# Do not set it larger than 30% of your available memory, as some memory
# is also required by the OS to cache rows. Even if you're not using
# MyISAM tables, you should still set it to 8-64M as it will also be
# used for internal temporary disk tables.
key_buffer_size=55M //表示关键词缓冲的大小
# Size of the buffer used for doing full table scans of MyISAM tables.
# Allocated per thread, if a full scan is needed.
read_buffer_size=64K //表示MyISAM表全表扫描的缓冲的大小
read_rnd_buffer_size=256K //表示将排序好的数据存入缓存中
# This buffer is allocated when MySQL needs to rebuild the index in
# REPAIR, OPTIMZE, ALTER table statements as well as in LOAD DATA INFILE
# into an empty table. It is allocated per thread so be careful with
# large settings.
sort_buffer_size=256K //表示用于排序的缓存的大小
#*** INNODB Specific options ***
# Use this option if you have a MySQL server with InnoDB support enabled
# but you do not plan to use it. This will save memory and disk space
# and speed up some things.
#skip-innodb
# Additional memory pool that is used by InnoDB to store metadata
# information. If InnoDB requires more memory for this purpose it will
# start to allocate it from the OS. As this is fast enough on most
# recent operating systems, you normally do not need to change this
# value. SHOW INNODB STATUS will display the current amount used.
innodb_additional_mem_pool_size=3M //表示附加的内存池
# If set to 1, InnoDB will flush (fsync) the transaction logs to the
# disk at each commit, which offers full ACID behavior. If you are
# willing to compromise this safety, and you are running small
# transactions, you may set this to 0 or 2 to reduce disk I/O to the
# logs. Value 0 means that the log is only written to the log file and
# the log file flushed to disk approximately once per second. Value 2
# means the log is written to the log file at each commit, but the log
# file is only flushed to disk approximately once per second.
innodb_flush_log_at_trx_commit=1 //设置为1,innoDb会在每次提交后将事务日志写到硬盘上
# The size of the buffer InnoDB uses for buffering log data. As soon as
# it is full, InnoDB will have to flush it to disk. As it is flushed
# once per second anyway, it does not make sense to have it very large
# (even with long transactions).
innodb_log_buffer_size=2M //日志缓冲的大小
# InnoDB, unlike MyISAM, uses a buffer pool to cache both indexes and
# row data. The bigger you set this the less disk I/O is needed to
# access data in tables. On a dedicated database server you may set this
# parameter up to 80% of the machine physical memory size. Do not set it
# too large, though, because competition of the physical memory may
# cause paging in the operating system. Note that on 32bit systems you
# might be limited to 2-3.5G of user level memory per process, so do not
# set it too high.
innodb_buffer_pool_size=106M //表示缓存的大小
# Size of each log file in a log group. You should set the combined size
# of log files to about 25%-100% of your buffer pool size to avoid
# unneeded buffer pool flush activity on log file overwrite. However,
# note that a larger logfile size will increase the time needed for the
# recovery process.
innodb_log_file_size=53M //日志文件的大小
# Number of threads allowed inside the InnoDB kernel. The optimal value
# depends highly on the application, hardware as well as the OS
# scheduler properties. A too high value may lead to thread thrashing.
innodb_thread_concurrency=10 //innoDb存储引擎允许的线程的最大数
=================================================================
basedir=C:\MySQL\MySQL Server 5.5
datadir=C:/mysql/appData --数据库路径
1、 命令行安装mysql
1、 注册服务
bin\mysqld --install mysql-5.5.15-win32 --defaults-file=d:\mysql-5.5.15-win32\my.ini
2、启动服务
net start mysql-5.5.15-win32
3、命令行登录
bin\mysql -u root -p
4、停止服务
net stop mysql-5.5.15-win32
5、删除服务
bin\mysqld --remove mysql-5.5.15-win32
6、启动服务不通过注册
bin\mysqld --console
7、停止服务不通过注册服务
bin\mysqladmin -u root shutdown
5、常用命令
1.列出MYSQL支持的所有字符集:
SHOW CHARACTER SET;
2.当前MYSQL服务器字符集设置
SHOW VARIABLES LIKE 'character_set_%';
3.当前MYSQL服务器字符集校验设置
SHOW VARIABLES LIKE 'collation_%';
4.显示某数据库字符集设置
show create database 数据库名;
5.显示某数据表字符集设置
show create table 表名;
6.修改数据库字符集
alter database 数据库名 default character set 'utf8';
7.修改数据表字符集
alter table 表名 default character set 'utf8';
8.建库时指定字符集
create database 数据库名 character set gbk collate gbk_chinese_ci;
=================================================================
开启远程连接
dos> mysql -u root -p 接下来会让你输入密码,登入到数据库后
mysql>select host, user from user;
2. 授权法。例如,你想myuser使用mypassword从任何主机连接到mysql服务器的话。
mysql>GRANT ALL PRIVILEGES ON *.* TO user_remote @'%' IDENTIFIED BY '12345' WITH GRANT OPTION;
mysql>FLUSH PRIVILEGES;
如果你想允许用户myuser从ip为192.168.1.6的主机连接到mysql服务器,并使用mypassword作为密码
mysql>GRANT ALL PRIVILEGES ON *.* TO 'myuser'@'192.168.0.2' IDENTIFIED BY '123456' WITH GRANT OPTION;
mysql>FLUSH PRIVILEGES;
mysql>FLUSH PRIVILEGES;