【centos7 + MySQL5.7 安装】centos7 安装MySQL5.7

分手后的思念是犯贱 2024-03-25 21:43 240阅读 0赞

说明:我们安装MySQL位置在 /usr/local 下

第一步、下载MySQL 安装包:

  1. [root@localhost local]# wget https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm

安装mysql 安装源:

  1. [root@localhost local]# yum -y localinstall mysql57-community-release-el7-11.noarch.rpm

第二步,在线安装MySQL

  1. [root@localhost local]# yum -y install mysql-community-server

等待时间比较久:

7e6c657911046e9f6ee055dc8694d951.png

第三步、启动mysql 服务

  1. [root@localhost local]# systemctl start mysqld

第四步,设置开机启动

  1. [root@localhost local]# systemctl enable mysqld
  2. [root@localhost local]# systemctl daemon-reload

第五步,修改root登录密码

mysql安装完成之后,会在/var/log/mysqld.log文件中给root生成了一个临时的默认密码。

  1. [root@localhost local]# vim /var/log/mysqld.log

3a7899e9c7020a4606c721868a783da8.png

记住初始密码:

修改root 密码

  1. [root@localhost local]# mysql -u root -p

0061bb7500c4e0c2852644b29a0bb087.png

  1. mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'daasan7ujm^YHN';
  2. Query OK, 0 rows affected (0.00 sec)
  3. # 设置远程登录
  4. mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'daasan7ujm^YHN' WITH GRANT OPTION;
  5. Query OK, 0 rows affected, 1 warning (0.00 sec)

第六步,退出

  1. mysql> exit

第七步,防火墙开放3306端口

  1. [root@localhost sysconfig]# cd /etc/sysconfig/
  2. [root@localhost sysconfig]# vim iptables
  3. #添加代码如下
  4. -A INPUT -p tcp --dport 3306 -j ACCEPT

710a69f25dfc680daf952ad2e3c68d7b.png

第八步,重启防火墙。

  1. [root@localhost sysconfig]# service iptables restart

第九步,配置mysql默认编码为utf-8

  1. [root@localhost sysconfig]# vim /etc/my.cnf

添加如下代码

  1. character_set_server=utf8
  2. init_connect='SET NAMES utf8'

e6c3a89a37faa8969c7e924fa4d9e153.png

:wq 保存退出

第十步,重启MySQL

  1. [root@localhost data]# systemctl restart mysqld

第十一步, root 用户登录查看编码

  1. [root@localhost sysconfig]# mysql -u root -p
  2. Enter password:
  3. Welcome to the MySQL monitor. Commands end with ; or \g.
  4. Your MySQL connection id is 2
  5. Server version: 5.7.29 MySQL Community Server (GPL)
  6. Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
  7. Oracle is a registered trademark of Oracle Corporation and/or its
  8. affiliates. Other names may be trademarks of their respective
  9. owners.
  10. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
  11. mysql> show variables like '%character%';
  12. +--------------------------+----------------------------+
  13. | Variable_name | Value |
  14. +--------------------------+----------------------------+
  15. | character_set_client | utf8 |
  16. | character_set_connection | utf8 |
  17. | character_set_database | utf8 |
  18. | character_set_filesystem | binary |
  19. | character_set_results | utf8 |
  20. | character_set_server | utf8 |
  21. | character_set_system | utf8 |
  22. | character_sets_dir | /usr/share/mysql/charsets/ |
  23. +--------------------------+----------------------------+
  24. 8 rows in set (0.00 sec)
  25. mysql>

最后本地连接测试:

d18cc3444c852272f7368b0d71096280.png

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。

本文链接:https://blog.csdn.net/EB_NUM/article/details/105425622

发表评论

表情:
评论列表 (有 0 条评论,240人围观)

还没有评论,来说两句吧...

相关阅读