windows10版本安装
1.获取mysql压缩包
https://dev.mysql.com/downloads/mysql/
2.解压并配置文件my.ini
1.解压的文件路径 D:\Program Files (x86)\mysql-8.0.11-winx642.my.ini 的文件路径 D:\Program Files (x86)\mysql-8.0.11-winx64\my.ini
配置my.ini文件
[mysql]#设置mysql客户端默认字符集default-character-set=utf8[mysqld]#设置3306端口port = 3306 #设置mysql的安装目录basedir=D:\Program Files (x86)\mysql-8.0.12-winx64#设置mysql数据库的数据的存放目录datadir=D:\Program Files (x86)\mysql-8.0.12-winx64\data#允许最大连接数max_connections=200#服务端使用的字符集默认为8比特编码的latin1字符集character-set-server=utf8#创建新表时将使用的默认存储引擎explicit_defaults_for_timestamp=truedefault-storage-engine=INNODB
3.在管理员身份运行cmd
3.1 安装mysqld
mysqld install
3.2 执行命令,初始化data目录,安装包中并没有data文件夹,运行命令后,会自动在D:\MySQL\mysql-8.0.11-winx64目录下生成data文件夹:
mysqld --initialize -user=mysql --console
箭头所指为初始密码
3.3启动mysql
net start mysql
4.修改密码
4.1 登录mysql
mysql -u root -p初始化的密码(需要填上一步初始化的密码,和p连接无空格)
4.2 修改密码
alter user ‘root‘@‘localhost‘ identified by ‘your password‘;
4.3 刷新权限
flush privieges;
5.在需要重新安装mysql的情况下,可以删除mysqld服务
mysqld --remove mysql
5.忘记密码
后补
Centos版本安装mysql
[root@virde ~]# wget https://repo.mysql.com//mysql80-community-release-el7-1.noarch.rpm[root@virde ~]# sudo yum localinstall mysql80-community-release-el7-1.noarch.rpm
[root@virde ~]# yum repolist enabled | grep "mysql.*-community.*"mysql-connectors-community/x86_64 MySQL Connectors Community 51mysql-tools-community/x86_64 MySQL Tools Community 63mysql80-community/x86_64 MySQL 8.0 Community Server 17
[root@virde ~]# sudo yum install mysql-community-server
[root@virde ~]# sudo service mysqld startStarting mysqld:[ OK ]
[root@virde ~]# sudo grep ‘temporary password‘ /var/log/mysqld.log2018-04-27T05:20:28.645777Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: nDjEy-#jv7Dn
[root@virde ~]# mysql -u root -pEnter password: Welcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 19Server version: 8.0.11 MySQL Community Server - GPL
mysql> ALTER USER ‘root‘@‘localhost‘ IDENTIFIED BY ‘Aa123456.‘;Query OK, 0 rows affected (0.08 sec)
mysql -u root -puse mysql;update user set host=‘%‘ where user=‘root‘;
4.2 使用授权的方式
mysql> GRANT ALL PRIVILEGES ON *.* TO ‘root‘@‘%‘WITH GRANT OPTION;mysql>FLUSH PRIVILEGES
4.3 新特性导致的错误并改正
4.3.1 mysql8.0 引入了新特性 caching_sha2_password;这种密码加密方式客户端不支持;客户端支持的是mysql_native_password 这种加密方式;
4.3.2 修改成mysql_native_password加密模式:
update user set plugin=‘mysql_native_password‘ where user=‘root‘;
5.忘记密码
https://blog.csdn.net/xinpengfei521/article/details/80400142