在centos上安装mysql5.7.x

mac2026-01-13  10

在centos上安装mysql5.7.x

快双十一,服务器大减价,搞了台服务器准备自己玩玩,先安装一下数据库,查阅了一下别人的博客搞定了,原博客文链接:https://blog.csdn.net/xqhys/article/details/90695745

1.更新服务器

yum update -y

2.下载并安装rpm源

wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm rpm -ivh mysql-community-release-el7-5.noarch.rpm

3.修改数据库版本

最开始安装的时候并没有搞这一步,默认安装的是5.6的,如果要安装5.7的可以 vim /etc/yum.repos.d/mysql-community.repo 源, 改变默认安装的mysql版本。比如要安装5.6版本,将5.7源的enabled=1改成enabled=0。然后再将5.6源的enabled=0改成enabled=1即可,改完如下

[mysql-connectors-community] name=MySQL Connectors Community baseurl=http://repo.mysql.com/yum/mysql-connectors-community/el/7/$basearch/ enabled=1 gpgcheck=1 gpgkey=file:/etc/pki/rpm-gpg/RPM-GPG-KEY-mysql [mysql-tools-community] name=MySQL Tools Community baseurl=http://repo.mysql.com/yum/mysql-tools-community/el/7/$basearch/ enabled=1 gpgcheck=1 gpgkey=file:/etc/pki/rpm-gpg/RPM-GPG-KEY-mysql # Enable to use MySQL 5.5 [mysql55-community] name=MySQL 5.5 Community Server baseurl=http://repo.mysql.com/yum/mysql-5.5-community/el/7/$basearch/ enabled=0 gpgcheck=1 gpgkey=file:/etc/pki/rpm-gpg/RPM-GPG-KEY-mysql # Enable to use MySQL 5.6 [mysql56-community] name=MySQL 5.6 Community Server baseurl=http://repo.mysql.com/yum/mysql-5.6-community/el/7/$basearch/ enabled=0 gpgcheck=1 gpgkey=file:/etc/pki/rpm-gpg/RPM-GPG-KEY-mysql # Note: MySQL 5.7 is currently in development. For use at your own risk. # Please read with sub pages: https://dev.mysql.com/doc/relnotes/mysql/5.7/en/ [mysql57-community-dmr] name=MySQL 5.7 Community Server Development Milestone Release baseurl=http://repo.mysql.com/yum/mysql-5.7-community/el/7/$basearch/ enabled=1 gpgcheck=1 gpgkey=file:/etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

4.安装数据库并启动

yum install mysql-community-server service mysqld status --查看有没有打开服务 service mysqld start --打开服务 service mysqld stop --停止服务 service mysqld restart --重启服务

5.修改数据库root密码

[root@localhost ~]# mysql -u root     Welcome to the MySQL monitor.  Commands end with ; or \g.     Your MySQL connection id is 2     Server version: 5.6.41 MySQL Community Server (GPL)     Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.     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> use mysql;     Reading table information for completion of table and column names     You can turn off this feature to get a quicker startup with -A     Database changed mysql> update user set authentication_string=password('321') where user = 'root';     Query OK, 4 rows affected (0.02 sec)     Rows matched: 4  Changed: 4  Warnings: 0 [root@localhost ~]# flush privileges; Query OK, 0 rows affected (0.02 sec) 接着执行: SELECT * from mysql.user\G; 去找到root用户的authentication_string这项,并把它的值记下来。 MySQL会给密码进行加密,你想要设置的密码进行加密后的值就等于此时authentication_string这项的值 所以接下来把Password这项的值也设置成此时authentication_string项的值就ok了;我设置的密码是321 ,其对应的密文是  *7297C3E22DEB91303FC493303A8158AD4231F486 执行下面两条sql语句: update mysql.user set password = '*7297C3E22DEB91303FC493303A8158AD4231F486' where user = 'root'; flush privileges;
最新回复(0)