Mysql解压版安装配置
1、下载压缩包
地址:
https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.20-winx64.zip
2、解压至任意不含中文的路径下
3、在根目录创建my.ini 文件,文件内容如下
注意修改端口及路径
[client] default-character-set=utf8 [mysqld] port=3306 basedir ="C:/BtSoft/mysql/mysql-5.7.20-winx64/" datadir ="C:/BtSoft/mysql/mysql-5.7.20-winx64/data/" tmpdir ="C:/BtSoft/mysql/mysql-5.7.20-winx64/data/" socket ="C:/BtSoft/mysql/mysql-5.7.20-winx64/data/mysql.sock" log-error="C:/BtSoft/mysql/mysql-5.7.20-winx64/data/mysql_error.log" log-bin=mysql-bin binlog_format=mixed server_id = 1 #skip-locking max_connections = 300 table_open_cache = 256 query_cache_size = 64M tmp_table_size = 32M thread_cache_size = 128 binlog_cache_size = 32K thread_stack = 256K read_buffer_size = 128K query_cache_type = 1 max_heap_table_size = 32M key_buffer_size = 128M innodb_data_home_dir="C:/BtSoft/mysql/mysql-5.7.20-winx64/data/" innodb_flush_log_at_trx_commit =1 innodb_log_buffer_size = 128M innodb_buffer_pool_size = 256M innodb_log_file_size=10M innodb_thread_concurrency=16 innodb-autoextend-increment=1000 join_buffer_size = 256K sort_buffer_size = 768K read_rnd_buffer_size = 512K max_allowed_packet = 32M explicit_defaults_for_timestamp=true sql-mode="STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION" [mysqldump] quick max_allowed_packet = 16M [mysql] no-auto-rehash [myisamchk] key_buffer_size = 20M sort_buffer_size = 20M read_buffer = 2M write_buffer = 2M [mysqlhotcopy] interactive-timeout
4、配置环境变量
4.1 新建系统环境变量
名称:MYSQL_HOME
值:解压的MySQL的路径
4.2 修改PATH
添加%MYSQL_HOME%\bin
5、安装MySQL服务
进入命令行,输入以下命令
mysqld install mysql57 --defaults-file="C:\BtSoft/mysql\mysql-5.7.20-winx64\my.ini"
其中“mysql57”为服务名称,可自定义
出现以下响应说明安装成功
6、执行初始化语句
C:\BtSoft/mysql\mysql-5.7.20-winx64\bin>mysqld --initialize
执行后无输出,此时之前在my.ini文件中定义的data路径中,已经自动初始化了若干个文件,如图
7、启动mysql57服务
net start mysql57
此时不出意外的话,MySQL服务已经启动成功了
现在进行登录,首先查找默认密码
打开DATA文件夹中的mysql_error.log文件,查找“password”
初识密码就是他了,如果查询不到password关键字,则可能初始密码为空
进入命令行
mysql -u root -p
Enter password: *********
输入之前查找到的密码即可
进入之后首先修改root密码
SET PASSWORD = PASSWORD('新密码');
关掉dos窗口,使用新密码重新登录mysql。
至此,MySQL安装完成。
但是MySQL默认是只支持以root账户在本机进行登录,下面修改配置
登录mysql
mysql> use mysql; Database changed
:: 查询当前user表访问权限设置 mysql> select user,host from user; +---------------+-----------+ | user | host | +---------------+-----------+ | mysql.session | localhost | | mysql.sys | localhost | | root | localhost | +---------------+-----------+ 3 rows in set (0.00 sec)
:: 将root用户的host修改为%,即任意主机都允许登录 mysql> update user set host='%' where user='root'; Query OK, 1 row affected (0.01 sec) Rows matched: 1 Changed: 1 Warnings: 0 mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'root' WITH GRANT OPTION; Query OK, 0 rows affected, 1 warning (0.00 sec) mysql> flush privileges; Query OK, 0 rows affected (0.01 sec) mysql>
设置完成,现在可以使用Navicat等工具连接MySQL数据库了