#这里是安装mysql的源 yum install -y https://repo.mysql.com//mysql80-community-release-el7-3.noarch.rpm
检查MySQL源是否安装成功
yum repolist enabled 部分结果: mysql-connectors-community/x86_64 MySQL Connectors Community mysql-tools-community/x86_64 MySQL Tools Community mysql80-community/x86_64 MySQL 8.0 Community Server
yum install mysql-community-server Transaction test succeeded Running transaction Installing : mysql-community-common-8.0.21-1.el7.x86_64 1/7 Installing : mysql-community-libs-8.0.21-1.el7.x86_64 2/7 Installing : mysql-community-client-8.0.21-1.el7.x86_64 3/7 Installing : net-tools-2.0-0.25.20131004git.el7.x86_64 4/7 Installing : mysql-community-server-8.0.21-1.el7.x86_64 5/7 Installing : mysql-community-libs-compat-8.0.21-1.el7.x86_64 6/7 Erasing : 1:mariadb-libs-5.5.65-1.el7.x86_64 7/7 Verifying : mysql-community-server-8.0.21-1.el7.x86_64 1/7 Verifying : mysql-community-libs-8.0.21-1.el7.x86_64 2/7 Verifying : mysql-community-client-8.0.21-1.el7.x86_64 3/7 Verifying : mysql-community-libs-compat-8.0.21-1.el7.x86_64 4/7 Verifying : net-tools-2.0-0.25.20131004git.el7.x86_64 5/7 Verifying : mysql-community-common-8.0.21-1.el7.x86_64 6/7 Verifying : 1:mariadb-libs-5.5.65-1.el7.x86_64 7/7 Installed: mysql-community-libs.x86_64 0:8.0.21-1.el7 mysql-community-libs-compat.x86_64 0:8.0.21-1.el7 mysql-community-server.x86_64 0:8.0.21-1.el7 Dependency Installed: mysql-community-client.x86_64 0:8.0.21-1.el7 mysql-community-common.x86_64 0:8.0.21-1.el7 net-tools.x86_64 0:2.0-0.25.20131004git.el7 Replaced: mariadb-libs.x86_64 1:5.5.65-1.el7
Total download size: 553 M
# 启动服务 systemctl start mysqld # 查看服务 systemctl status mysqld mysqld.service - MySQL Server Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled) Active: active (running) since Sat 2020-08-01 16:06:52 EDT; 12s ago
先在日志中查找 生成的密码
grep 'temporary password' /var/log/mysqld.log [root@bogon ~]# grep 'temporary password' /var/log/mysqld.log 2020-08-01T20:06:49.105603Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: J<wGLsguq9?n
mysql -u root -p 不过进行其他操作的时候,会发现 提示你用alert 语句去修改密码,这个密码只是临时密码。 mysql> use mysql ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
# ALTER USER 'root'@'localhost' IDENTIFIED BY '密码';
xxxxxxxxxx mysql> show global variables like '%validate_password%';+--------------------------------------+--------+| Variable_name | Value |+--------------------------------------+--------+| validate_password.check_user_name | ON || validate_password.dictionary_file | || validate_password.length | 8 || validate_password.mixed_case_count | 1 || validate_password.number_count | 1 || validate_password.policy | MEDIUM || validate_password.special_char_count | 1 |+--------------------------------------+--------+# 解释validate_password_dictionary_file :验证密码的字典文件,与之相同的不可使用validate_password_length :密码最少长度validate_password_number_count :最少数字字符数validate_password_mixed_case_count :最少大写和小写字符数(同时有大写和小写)validate_password_special_char_count :最少特殊字符数validate_password_policy :密码安全策略 LOW: 只限制长度 MEDIUM: 限制长度、数字、字母、特殊字符 STRONG: 限制长度、数字、字母、特殊字符、字典#默认是中等,密码必须由 大写字母、小写字母、数字、特殊字符组成 且长度为8位
选择0(LOW),1(MEDIUM),2(STRONG)其中一种,选择2需要提供密码字典文件
validate_password_policy=0
validate_password = off
systemctl restart mysqld
MySQL默认只允许root帐户在本地登录,想要远程连接MySQL,必须开启root用户允许远程连接,或者添加一个允许远程连接的帐户。
首先查看mysql的 user表
select * from user \G *************************** 4. row *************************** Host: localhost User: root Select_priv: Y Insert_priv: Y Update_priv: Y Delete_priv: Y Create_priv: Y Drop_priv: Y Reload_priv: Y Shutdown_priv: Y Process_priv: Y File_priv: Y Grant_priv: Y References_priv: Y Index_priv: Y Alter_priv: Y Show_db_priv: Y Super_priv: Y Create_tmp_table_priv: Y Lock_tables_priv: Y Execute_priv: Y Repl_slave_priv: Y Repl_client_priv: Y Create_view_priv: Y Show_view_priv: Y Create_routine_priv: Y Alter_routine_priv: Y Create_user_priv: Y Event_priv: Y Trigger_priv: Y Create_tablespace_priv: Y ssl_type: ssl_cipher: 0x x509_issuer: 0x x509_subject: 0x max_questions: 0 max_updates: 0 max_connections: 0 max_user_connections: 0 plugin: caching_sha2_password authentication_string: $A$005$QVf` hi@? _:w.FDDatpHPPpgl.7j830gDg9X.HbKF05PzcdmXptHuD password_expired: N password_last_changed: 2020-08-03 20:01:07 password_lifetime: NULL account_locked: N Create_role_priv: Y Drop_role_priv: Y Password_reuse_history: NULL Password_reuse_time: NULL Password_require_current: NULL User_attributes: NULL 4 rows in set (0.01 sec)
查询mysql具体版本
SELECT @@VERSION mysql> select @@VERSION; +-----------+ | @@VERSION | +-----------+ | 8.0.21 | +-----------+
早期可以合二为一
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '密码' WITH GRANT OPTION;
创建可以远程访问的root用户
create user 'root'@'%' identified by '密码';
给远程root用户赋予权限
grant all privileges on *.* to 'root'@'%' with grant option;
操作后要执行刷新,远程用户才能有效
flush privileges;
查看数据库使用的字符集
show variables like '%character%%'
在 /etc/my.cnf文件[mysqld]下面加如下命令
[mysqld] skip-grant-tables #设置为跳过授权认证 不验证密码 mysql -u root #update mysql.user set authentication_string=password('newPass') where user='root' and #Host = 'localhost'; flush privileges ALTER USER 'root'@'localhost' IDENTIFIED BY '密码'; flush privileges