MYSQL安装
从官网选择对应的版本下载64位的zip包:
https://dev.mysql.com/downloads/mysql/
备注:正常来说下载第一个,第二个是调试版本,下载之后解压到文件夹,不要有中文目录
解压后新建一个my.ini,内容如下,需要修改basedir和datadir
# 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]
port = 3306
default-character-set = utf8
[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
port = 3306
# These are commonly set, remove the # and set as required.
basedir="D:\...\mysql"
datadir="D:\...\mysql/data/"
# server_id = .....
character_set_server = utf8
# 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
增加环境变量
变量:MYSQL_HOME
值:F:\Workspace\mysql-8.0.24-winx64
在path中增加:%MYSQL_HOME\bin
切换到bin目录下初始化数据库:mysqld --initialize-insecure --user=mysql
安装数据库:mysqld –install
报错:Install/Remove of the Service Denied!
解决办法:以管理员身份运行
报错:The service already exists! 说明之前安装过,把之前的删掉重新安装
查询是否安装过:sc query mysql
删除安装的mysql: sc delete mysql
显示:Service successfully installed. 证明已经安装成功
启动服务:net start mysql
关闭服务:net stop mysql
卸载服务:mysql --remove
登录数据库:mysql –u root -p 回车直接登录
显示数据库:show databases;
输入:user mysql;
修改密码语句:ALTER USER ‘root’@‘localhost’ IDENTIFIED BY ‘admin123’;
更新权限:flush privileges;
退出:quit;
客户端连接mysql报错:1251 client does not support
解决:
查看用户信息:select host,user,plugin,authentication_string from mysql.user;
修改密码
修改用户密码
ALTER USER ‘root’@’%’ IDENTIFIED WITH mysql_native_password BY ‘admin123’;
备注:这个需要给root用户开启远程权限,不然执行会报错:ERROR 1396 (HY000): Operation ALTER USER failed for ‘root’@’%’,因为‘%’是指所有远程终端都可以连接登录
ALTER USER ‘root’@‘localhost’ IDENTIFIED WITH mysql_native_password BY ‘admin123’;
修改后连接成功