下载地址:https://dev.mysql.com/downloads/mysql/
变量名:MYSQL_HOME
变量值:E:\mysql-5.7.20-winx64(安装目录)
进入E:\python\mysql\mysql-8.0.12-winx64\bin>下
执行命令:mysqld --initialize-insecure --user=mysql 在E:\python\mysql\mysql-8.0.12-winx64\bin目录下生成data目录
继续执行命令:mysqld -install
继续执行命令:net start MySQL
登录mysql:(因为之前没设置密码,所以密码为空,不用输入密码,直接回车即可)
E:\python\mysql\mysql-8.0.12-winx64\bin>mysql -u root -p
mysql> use mysql mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '123456'; mysql> flush privileges;
-- 赋值权限 -- root 用户名 -- % 表示剋访问任意ip mysql 8.0 之后: grant all privileges on *.* to 'root'@'localhost'; mysql 8.0之前: GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION; -- 刷新mysql服务 flush privileges; -- service mysql restart(liunx 重启mysql服务)
# 创建用户 create user '用户名'@'localhost' identified by '密码'; # 分配权限 grant all privileges on *.* to '用户名'@'localhost'; #登录 mysql -uroot -ppassword use mysql; #选择数据库 # 远程连接请将'localhost'换成'%' ALTER USER 'root'@'localhost' IDENTIFIED BY 'password' PASSWORD EXPIRE NEVER; #更改加密方式 ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password'; #更新用户密码 FLUSH PRIVILEGES; #刷新权限
# 连接mysql mysql -h主机地址 -u用户名 -p密码 例1:假设远程主机的IP为:110.110.110.110,用户名为root,密码为abcd123。则键入以下命令: mysql -h110.110.110.110 -uroot -pabcd123 (注:u与root可以不用加空格,其它也一样) # 退出mysql exit # 修改密码 mysqladmin -u 用户名 -p旧密码 password 新密码