MySQL8.0 Windows zip包下载地址:https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-8.0.11-winx64.ziphtml
环境:Windows 10mysql
好比个人安装目录是:D:\Program\MySQLlinux
在Windows系统中,配置文件默认是安装目录下的 my.ini 文件,部分配置须要在初始安装时配置,大部分也能够在安装完成后进行更改。固然,极端状况下,全部的都是能够更改的。sql
在安装根目录下添加 my.ini,好比我这里是:D:\Program\MySQL\my.ini,写入基本配置:shell
[mysqld] # 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 = D:\Program\MySQL datadir = D:\DBs\MySQL port = 3306 # 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 character-set-server = utf8mb4 performance_schema_max_table_instances = 600 table_definition_cache = 400 table_open_cache = 256 [mysql] default-character-set = utf8mb4 [client] default-character-set = utf8mb4
注意,里面的 basedir 是我本地的安装目录,datadir 是我数据库数据文件要存放的位置,各项配置须要根据本身的环境进行配置。数据库
查看全部的配置项,可参考:https://dev.mysql.com/doc/refman/8.0/en/mysqld-option-tables.htmlwindows
在MySQL安装目录的 bin 目录下执行命令:安全
mysqld --initialize --console
执行完成后,会打印 root 用户的初始默认密码,好比:工具
2018-04-20T02:35:01.507037Z 0 [Warning] [MY-010915] [Server] 'NO_ZERO_DATE', 'NO_ZERO_IN_DATE' and 'ERROR_FOR_DIVISION_BY_ZERO' sql modes should be used with strict mode. They will be merged with strict mode in a future release. 2018-04-20T02:35:01.507640Z 0 [System] [MY-013169] [Server] D:\Program\MySQL8\bin\mysqld.exe (mysqld 8.0.11) initializing of server in progress as process 11064 2018-04-20T02:35:01.508173Z 0 [ERROR] [MY-010340] [Server] Error message file 'D:\Program\MySQL\share\english\errmsg.sys' had only 1090 error messages, but it should contain at least 4512 error messages. Check that the above file is the right version for this program! 2018-04-20T02:35:05.464644Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: APWCY5ws&hjQ 2018-04-20T02:35:07.017280Z 0 [System] [MY-013170] [Server] D:\Program\MySQL8\bin\mysqld.exe (mysqld 8.0.11) initializing of server has completed
其中,第4行的“APWCY5ws&hjQ”就是初始密码,在没有更改密码前,须要记住这个密码,后续登陆须要用到。测试
要是你手贱,关快了,或者没记住,那也没事,删掉初始化的 datadir 目录,再执行一遍初始化命令,又会从新生成的。固然,也可使用安全工具,强制改密码,用什么方法,本身随意。
参考:https://dev.mysql.com/doc/refman/8.0/en/data-directory-initialization-mysqld.html
在MySQL安装目录的 bin 目录下执行命令:
mysqld --install [服务名]
后面的服务名能够不写,默认的名字为 mysql。固然,若是你的电脑上须要安装多个MySQL服务,就能够用不一样的名字区分了,好比 mysql5 和 mysql8。
安装完成以后,就能够经过命令net start mysql启动MySQL的服务了。
参考:https://dev.mysql.com/doc/refman/8.0/en/windows-start-service.html
在MySQL安装目录的 bin 目录下执行命令:
mysql -uroot -p
这时候会提示输入密码,记住了第3步的密码,填入便可登陆成功,进入MySQL命令模式。
在MySQL8.0.4之前,执行
SET PASSWORD=PASSWORD('[修改的密码]');
就能够更改密码,可是MySQL8.0.4开始,这样默认是不行的。由于以前,MySQL的密码认证插件是“mysql_native_password”,而如今使用的是“caching_sha2_password”。
由于当前有不少数据库工具和连接包都不支持“caching_sha2_password”,为了方便,我暂时仍是改回了“mysql_native_password”认证插件。
在MySQL中执行命令:
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';
修改密码验证插件,同时修改密码。
若是想默认使用“mysql_native_password”插件认证,能够在配置文件中配置default_authentication_plugin
项。
[mysqld] default_authentication_plugin=mysql_native_password
不用测了,官方说MySQL8比5快两倍。
wget https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-8.0.11-linux-glibc2.12-x86_64.tar.gz shell> tar zxvf mysql-8.0.11-linux-glibc2.12-x86_64.tar.gz -C /usr/local/ shell> groupadd mysql shell> useradd -r -g mysql -s /bin/false mysql shell> cd /usr/local shell> ln -s mysql-8.0.11-linux-glibc2.12-x86_64 mysql shell> cd mysql shell> mkdir mysql-files shell> chown mysql:mysql mysql-files shell> chmod 750 mysql-files shell> bin/mysqld --initialize --user=mysql shell> bin/mysql_ssl_rsa_setup shell> bin/mysqld_safe --user=mysql & # Next command is optional shell> cp support-files/mysql.server /etc/init.d/mysql.server
参考:https://dev.mysql.com/doc/refman/8.0/en/binary-installation.html
在windos 的cmd下安装mysql
在mysql的bin目录下面执行: mysqld --install
报错:
信息以下:
Install/Remove of the Service Denied
解决办法:
打开cmd.exe程序的时候选择“用管理员身份打开”。