一、下载mysql
1、下载mysql
mysql最新版本下载地址:https://dev.mysql.com/downloads/mysql/
mysql存档旧版下载地址:https://downloads.mysql.com/archives/community
2、解压mysql
将下载的mysql-8.0.22-winx64.zip文件解压到指定的目录并重命名,如:D:\wamp\mysql80,即为mysql的安装目录。
二、安装mysql
1、设置PATH环境变量,右键“我的电脑-高级系统设置-环境变量-系统变量-path”,双击编辑将mysql 安装目录D:\wamp\mysql80\bin加入path中。
2、右键点击windows10右下角开始菜单,选择以管理员运行powershell,命令行进入到mysql的安装目录:
> cd d:\wamp\mysql80\bin
3、初始化mysql:
> .\mysqld --initialize --console
记下运行结果中随机生成的root密码,方便后期修改root密码。root@localhost: W/62jqidawwN
4、安装mysql服务:
> .\mysqld --install
5、启动mysql服务:
>net start mysql
6、登录、修改mysql密码:
>mysql -uroot -p
输入初始化的root密码
mysql>ALTER USER 'root'@'localhost' identified by '123456' PASSWORD EXPIRE NEVER;
mysql>flush privileges;
说明:mysql8.0开始密码认证插件默认为“caching_sha2_password”。但只有php7.1.20、7.1.21、7.1.22、7.2.8、7.2.9、7.2.10及php7.4以上版本才支持。除此,需要将mysql8.0的密码认证插件改为“mysql_native_password”。
mysql>ALTER USER 'root'@'localhost' identified with mysql_native_password by '123456';
mysql>flush privileges;
或者编辑mysql配置文件,更改默认的身份认证插件。在[mysqld]下添加:
default_authentication_plugin=mysql_native_password
7、开启php的mysql扩展,支持php连接mysql:
编辑d:/wamp/php72/php.ini,将extension=mysqli和extension=pdo_mysql前面的分号去掉后,重启apache:
>httpd -k restart
8、mysql8导入sql文件需指定字符编码,否则乱码报错:
>mysql -uroot -p --default-character-set=utf8mb4 testdb -e "source d:\test.sql"
如:mysql 8 ERROR 1064 (42000) at line ': You have an error in your SQL syntax; check the manual that c
9.创建my.ini配置文件,内容如下:
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html
# *** DO NOT EDIT THIS FILE. It's a template which will be copied to the
# *** default location during install, and will be replaced if you
# *** upgrade to a newer version of MySQL.
[client]
default-character-set = utf8mb4
[mysql]
default-character-set = utf8mb4
[mysqld]
# basedir = d:\wamp\mysql80
# datadir = d:\wamp\mysql80\data
# port = 3306
character-set-client-handshake = FALSE
character-set-server = utf8mb4
collation-server = utf8mb4_bin
init_connect = 'SET NAMES utf8mb4'
innodb_buffer_pool_size = 128M
join_buffer_size = 128M
sort_buffer_size = 16M
read_rnd_buffer_size = 16M
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
# These are commonly set, remove the # and set as required.
# basedir = .....
# datadir = .....
# port = .....
# server_id = .....
# 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 = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES