学习需要,自己更新
mysql的安装
1.下载
官网:https://dev.mysql.com/downloads/mysql/5.7.html#downloads
版本:windows x64位 下载到本地zip包
下载到本地
2.安装
2.1解压zip包到d盘,配置参数
目录形如:D:\mysql-5.7.35-winx64
在目录下建立1个文件 my.ini 和一个文件夹data
[mysqld]
##skip-grant-tables=1
port = 3306
basedir=D:\mysql-5.7.35-winx64
datadir=D:\mysql-5.7.35-winx64\data
max_connections=200
character-set-server=utf8
default-storage-engine=INNODB
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
[mysql]
default-character-set=utf8
注意新建my.ini的编码格式为ANSI
2.2设置环境变量
在系统变量部分新建一个变量名:MYSQL_HOME, 变量值:D:\mysql-5.7.35-winx64
在PATH里面新增路径 D:\mysql-5.7.35-winx64\bin
管理员运行CMD
cd D:\work\ls\mysql\mysql-5.7.23-winx64\bin
1.初始化数据库:
mysqld --initialize --user=mysql --console
PS D:\mysql-5.7.35-winx64\bin> mysqld --initialize --user=mysql --console
2021-09-04T04:57:55.038667Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2021-09-04T04:57:55.038774Z 0 [Warning] '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.
2021-09-04T04:57:55.038778Z 0 [Warning] 'NO_AUTO_CREATE_USER' sql mode was not set.
2021-09-04T04:57:55.159359Z 0 [Warning] InnoDB: New log files created, LSN=45790
2021-09-04T04:57:55.188318Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2021-09-04T04:57:55.260501Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: aa92f7ab-0d3c-11ec-99c8-482ae314fb42.
2021-09-04T04:57:55.264119Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2021-09-04T04:57:56.881452Z 0 [Warning] A deprecated TLS version TLSv1 is enabled. Please use TLSv1.2 or higher.
2021-09-04T04:57:56.881874Z 0 [Warning] A deprecated TLS version TLSv1.1 is enabled. Please use TLSv1.2 or higher.
2021-09-04T04:57:56.882975Z 0 [Warning] CA certificate ca.pem is self signed.
2021-09-04T04:57:57.379914Z 1 [Note] A temporary password is generated for root@localhost: WE#(hBQ_y8Pa
PS D:\mysql-5.7.35-winx64\bin>
其中 A temporary password is generated for root@localhost: WE#(hBQ_y8Pa 这个是临时密码
2.运行:mysqld -install (安装)
3.运行:net start mysql (启动mysql服务)
3.登录:
输入命令行mysql -uroot -p,利用之前的临时密码输入即可登录数据库成功。
PS D:\mysql-5.7.35-winx64\bin> mysql -uroot -p Enter password: ************ Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 2 Server version: 5.7.35 Copyright (c) 2000, 2021, Oracle and/or its affiliates. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql>
4.更新root用户密码
更新密码root
SET PASSWORD FOR 'root'@'localhost' = PASSWORD('root');
还可以设置远程和本地不同密码
分别设置本地和远程登录密码,密码可不同
mysql> update mysql.user set password=password('root') where user='root' and host='localhost';
mysql> update mysql.user set password=password('root1') where user='root' and host='%';
update mysql.user set password=password('123') where user='root' and host='BI-162';
mysql> flush privileges;
5.远程服务器访问授权
给远程服务器赋权,允许用户在指定IP进行远程登陆,如果想不限制链接的IP则设置为“%”即可
在安装mysql的机器上运行:
1、d:\mysql\bin>mysql -h localhost -u root
//这样应该可以进入MySQL服务器
2、mysql>GRANT ALL PRIVILEGES ON . TO 'root'@'%'WITH GRANT OPTION
//赋予任何主机访问数据的权限
例如,你想myuser使用mypassword从任何主机连接到mysql服务器的话。
GRANT ALL PRIVILEGES ON . TO 'myuser'@'%'IDENTIFIED BY 'mypassword' WITH GRANT OPTION;
如果你想允许用户myuser从ip为192.168.1.6的主机连接到mysql服务器,并使用mypassword作为密码
GRANT ALL PRIVILEGES ON . TO 'myuser'@'192.168.1.3'IDENTIFIED BY 'mypassword' WITH GRANT OPTION;
3、mysql>FLUSH PRIVILEGES
//修改生效
4、mysql>EXIT
//退出MySQL服务器,这样就可以在其它任何的主机上以root身份登录