博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
MySql安装
阅读量:7257 次
发布时间:2019-06-29

本文共 7771 字,大约阅读时间需要 25 分钟。

hot3.png

一、下载:

地址:

windows-64: 

windows-32: 

二、解压:

将下载的解压到安装目录D:\apply\mysql_5.7.19_winx64,其目录结构如下:

三、配置:

1、设置环境变量:

  添加环境变量名为“MYSQL_HOME”的变量,值:“D:\apply\mysql-5.7.19-winx64”

  修改环境变量“Path”,在最前面增加“%MYSQL_HOME%\bin;”。

2、配置ini文件:

  5.7.18版本以后的MySQL需要手动创建配置文件mysql.ini,然后放置到D:\apply\mysql-5.7.19-winx64\目录下。

  下面链接有一份详细说明:

mysql.ini的内容如下:

[client]port=3306default-character-set=utf8[WinMySQLAdmin]D:\apply\mysql-5.7.19-winx64\bin\mysqld.exe[mysql]#设置mysql客户端默认字符集default-character-set=utf8[mysqld]# 基准路径,其他路径都相对于这个路径basedir = "D:\apply\mysql-5.7.19-winx64"# mysql数据库文件所在目录      datadir = "D:\apply\mysql-5.7.19-winx64\data"tmpdir = "D:\apply\mysql-5.7.19-winx64\data"socket = "D:\apply\mysql-5.7.19-winx64\data\mysql.sock"log-error = "D:\apply\mysql-5.7.19-winx64\data\mysql_error.log"# mysql服务端默认监听(listen on)的TCP/IP端口port = 3306# server_id = .....#密码永久有效default_password_lifetime=0 #服务端使用的字符集默认为8比特编码的latin1字符集character-set-server=utf8# mysql服务器支持的最大并发连接数(用户数)。但总会预留其中的一个连接给管理员使用超级权限登录,即使连接数目达到最大限制。如果设置得过小而用户比较多,会经常出现“Too many connections”错误。max_connections = 100# 这个参数在5.1.3之后的版本中叫做table_open_cache,用于设置table高速缓存的数量。由于每个客户端连接都会至少访问一个表,因此此参数的值与       max_connections有关。当某一连接访问一个表时,MySQL会检查当前已缓存表的数量。如果该表已经在缓存中打开,则会直接访问缓存中的表已加快查询速度;如果该表未被缓存,则会将当前的表添加进缓存并进行查询。在执行缓存操作之前,table_cache用于限制缓存表的最大数目:如果当前已经缓存的表未达到table_cache,则会将新表添加进来;若已经达到此值,MySQL将根据缓存表的最后查询时间、查询率等规则释放之前的缓存。table_open_cache = 256# 查询缓存大小,用于缓存SELECT查询结果。如果有许多返回相同查询结果的SELECT查询,并且很少改变表,可以设置query_cache_size大于0,可以极大改善查询效率。而如果表数据频繁变化,就不要使用这个,会适得其反query_cache_size = 1M# 内存中的每个临时表允许的最大大小。如果临时表大小超过该值,临时表将自动转为基于磁盘的表(Disk Based Table)。tmp_table_size = 32M# 缓存的最大线程数。当客户端连接断开时,如果客户端总连接数小于该值,则处理客户端任务的线程放回缓存。在高并发情况下,如果该值设置得太小,就会有很多线程频繁创建,线程创建的开销会变大,查询效率也会下降。一般来说如果在应用端有良好的多线程处理,这个参数对性能不会有太大的提高。thread_cache_size = 8#创建新表时将使用的默认存储引擎default-storage-engine=INNODBinnodb_data_home_dir = "D:\apply\mysql-5.7.19-winx64\data"innodb_flush_log_at_trx_commit = 1innodb_log_buffer_size = 128Minnodb_buffer_pool_size = 128Minnodb_log_file_size = 10Minnodb_thread_concurrency = 16innodb-autoextend-increment = 1000# Remove leading # to set options mainly useful for reporting servers.# The server defaults are faster for transactions and fast SELECTs.# Adjust sizes as needed, experiment to find the optimal values.join_buffer_size = 128Msort_buffer_size = 2Mread_rnd_buffer_size = 2M #限制server接受的数据包大小max_allowed_packet = 32Mexplicit_defaults_for_timestamp = true # SQL模式为strict模式sql_mode=STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION,NO_ZERO_DATE,NO_ZERO_IN_DATE,ERROR_FOR_DIVISION_BY_ZERO#sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

四、注册MySql服务:

1、以管理员身份运行cmd,然后进入 bin 目录下:

C:\Windows\system32>d:D:\>cd %mysql_home%/binD:\apply\mysql-5.7.19-winx64\bin>

2、安装服务:

显示帮助信息如下:

D:\apply\mysql-5.7.19-winx64\bin>mysqld --verbose --help |moreUsage: mysqld [OPTIONS]NT and Win32 specific options:  --install                     Install the default service (NT).  --install-manual              Install the default service started manually (NT).  --install service_name        Install an optional service (NT).  --install-manual service_name Install an optional service started manually (NT).  --remove                      Remove the default service from the service list (NT).  --remove service_name         Remove the service_name from the service list (NT).  --enable-named-pipe           Only to be used for the default server (NT).  --standalone                  Dummy option to start as a standalone server (NT).Default options are read from the following files in the given order:C:\Windows\my.ini C:\Windows\my.cnf C:\my.ini C:\my.cnf D:\apply\mysql-5.7.19-winx64\my.ini D:\apply\mysql-5.7.19-winx64\my.cnfThe following groups are read: mysqld server mysqld-5.7The following options may be given as the first argument:--print-defaults        Print the program argument list and exit.--no-defaults           Don't read default options from any option file,                        except for login file.--defaults-file=#       Only read default options from the given file #.…………………………………………--initialize        Create the default database and exit. Create a super user                      with a random expired password and store it into the log.--initialize-insecure                      Create the default database and exit. Create a super user                      with empty password.

初始化、安装服务、启动服务的命令:

D:\apply\mysql-5.7.19-winx64\bin>mysqld --initialize-insecureD:\apply\mysql-5.7.19-winx64\bin>mysqld install MySQL_EXAMPLE_SERVICE --defaults-file="%MYSQL_HOME%\mysql.ini"Service successfully installed.D:\apply\mysql-5.7.19-winx64\bin>net start MySQL_EXAMPLE_SERVICEMySQL_EXAMPLE_SERVICE 服务正在启动 .MySQL_EXAMPLE_SERVICE 服务已经启动成功。D:\apply\mysql-5.7.19-winx64\bin>

五、修改root密码:

服务启动成功之后,就可以登录了,输入mysql -u root –p按回车键,出现Enter password,因为没有设置登录密码,所以什么都不用输入,直接按回车键即可。

D:\apply\mysql-5.7.19-winx64\bin>mysql -u root -pEnter password:Welcome to the MySQL monitor.  Commands end with ; or \g.Your MySQL connection id is 3Server version: 5.7.18 MySQL Community Server (GPL)Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql> alter user root@localhost identified by "12345";Query OK, 0 rows affected (0.01 sec)mysql> quit

使用命令:

alter user root@localhost identified by "12345";或者show databases;use mysql;UPDATE user SET authentication_string = PASSWORD('12345') WHERE user = 'root';FLUSH PRIVILEGES;

六、登录使用:

 

D:\apply\mysql-5.7.19-winx64\bin>mysql -uroot -prootmysql: [Warning] Using a password on the command line interface can be insecure.Welcome to the MySQL monitor.  Commands end with ; or \g.Your MySQL connection id is 11Server version: 5.7.18 MySQL Community Server (GPL)Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql> show databases;+--------------------+| Database           |+--------------------+| information_schema || mysql              || performance_schema || sys                |+--------------------+4 rows in set (0.00 sec)mysql> use mysqlDatabase changedmysql> show tables;+---------------------------+| Tables_in_mysql           |+---------------------------+| columns_priv              || db                        || engine_cost               || event                     || func                      || general_log               || gtid_executed             || help_category             || help_keyword              || help_relation             || help_topic                || innodb_index_stats        || innodb_table_stats        || ndb_binlog_index          || plugin                    || proc                      || procs_priv                || proxies_priv              || server_cost               || servers                   || slave_master_info         || slave_relay_log_info      || slave_worker_info         || slow_log                  || tables_priv               || time_zone                 || time_zone_leap_second     || time_zone_name            || time_zone_transition      || time_zone_transition_type || user                      |+---------------------------+31 rows in set (0.00 sec)mysql>

 

七、停止服务:

 

D:\apply\mysql-5.7.19-winx64\bin>net stop MySQL_EXAMPLE_SERVICEMySQL_EXAMPLE_SERVICE 服务正在停止.MySQL_EXAMPLE_SERVICE 服务已成功停止。

八、删除服务:

D:\apply\mysql-5.7.19-winx64\bin>mysqld remove MySQL_EXAMPLE_SERVICE

=====================end=============

转载于:https://my.oschina.net/mengyoufengyu/blog/1542613

你可能感兴趣的文章