Linux下部署mysql

[root@izm5e33l0ge76uqi8nq87az]# cd etc/yum.repos.d
[root@izm5e33l0ge76uqi8nq87az yum.repos.d]# ls
CentOS-Base.repo  epel.repo  mongodb-org-4.0.repo  nodesource-el7.repo
  • 安装配置源
[root@izm5e33l0ge76uqi8nq87az yum.repos.d]# rpm -ivh http://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm
获取http://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm
警告:/var/tmp/rpm-tmp.RsV9b3: 头V3 DSA/SHA1 Signature, 密钥 ID 5072e1f5: NOKEY
准备中...                          ################################# [100%]
正在升级/安装...
   1:mysql57-community-release-el7-11 ################################# [100%]
[root@izm5e33l0ge76uqi8nq87az yum.repos.d]# ls
CentOS-Base.repo  mongodb-org-4.0.repo  mysql-community-source.repo
epel.repo         mysql-community.repo  nodesource-el7.repo
  • 打开mysql-community.repo 查看默认打开的mysql源默认为5.7

[root@izm5e33l0ge76uqi8nq87az yum.repos.d]# vim mysql-community.repo


[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

[mysql57-community]
name=MySQL 5.7 Community Server
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

[mysql80-community]
name=MySQL 8.0 Community Server
baseurl=http://repo.mysql.com/yum/mysql-8.0-community/el/7/$basearch/
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

[mysql-tools-preview]
name=MySQL Tools Preview
baseurl=http://repo.mysql.com/yum/mysql-tools-preview/el/7/$basearch/
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

[mysql-cluster-7.5-community]
name=MySQL Cluster 7.5 Community
baseurl=http://repo.mysql.com/yum/mysql-cluster-7.5-community/el/7/$basearch/
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

[mysql-cluster-7.6-community]
name=MySQL Cluster 7.6 Community
baseurl=http://repo.mysql.com/yum/mysql-cluster-7.6-community/el/7/$basearch/
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
                                                              64,1         底端
  • 安装 yum -y install mysql-server
[root@izm5e33l0ge76uqi8nq87az yum.repos.d]# yum -y install mysql-server
已加载插件:fastestmirror
base                                                     | 3.6 kB     00:00     
epel                                                     | 4.7 kB     00:00     
....
已安装:
  mysql-community-libs.x86_64 0:5.7.26-1.el7                                    
  mysql-community-libs-compat.x86_64 0:5.7.26-1.el7                             
  mysql-community-server.x86_64 0:5.7.26-1.el7                                  

作为依赖被安装:
  libaio.x86_64 0:0.3.109-13.el7                                                
  mysql-community-client.x86_64 0:5.7.26-1.el7                                  
  mysql-community-common.x86_64 0:5.7.26-1.el7                                  

作为依赖被升级:
  postfix.x86_64 2:2.10.1-7.el7                                                 

替代:
  mariadb-libs.x86_64 1:5.5.56-2.el7                                            

完毕!
[root@izm5e33l0ge76uqi8nq87az yum.repos.d]# 
  • 启动 systemctl start mysqld
  • 开机启动 systemctl enable mysqld
  • 修改 MySQL root 本地登录密码
  • 登录 mysql -u root -p
  • 查看默认密码 cat /var/log/mysqld.log | grep password
[root@izm5e33l0ge76uqi8nq87az /]# cat /var/log/mysqld.log | grep password
2019-05-16T07:39:07.625478Z 1 [Note] A temporary password is generated for root@localhost: fl.oiCTZY1He
2019-05-16T07:49:40.884287Z 2 [Note] Access denied for user 'root'@'localhost' (using password: NO)
[root@izm5e33l0ge76uqi8nq87az /]# mysql -u root -p
Enter password: 
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
[root@izm5e33l0ge76uqi8nq87az /]# mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.26

Copyright (c) 2000, 2019, 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> 
  • 修改密码策略 vim etc/my.cnf
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html

[mysqld]
#
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
#
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
#
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock

# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0

log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
添加
validate_password = off
  • 配置完成后重启mysql服务并登录修改密码
  • systemctl restart mysqld
  • mysql -u root -p
  • ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';
[root@izm5e33l0ge76uqi8nq87az /]# vim etc/my.cnf
[root@izm5e33l0ge76uqi8nq87az /]# systemctl restart mysqld
[root@izm5e33l0ge76uqi8nq87az /]# mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.26

Copyright (c) 2000, 2019, 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> ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';
Query OK, 0 rows affected (0.00 sec)

mysql> 
  • 远程管理mysql
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> select * from user;
+-----------+---------------+-------------+-------------+-------------+-------------+-------------+-----------+-------------+---------------+--------------+-----------+------------+-----------------+------------+------------+--------------+------------+-----------------------+------------------+--------------+-----------------+------------------+------------------+----------------+---------------------+--------------------+------------------+------------+--------------+------------------------+----------+------------+-------------+--------------+---------------+-------------+-----------------+----------------------+-----------------------+-------------------------------------------+------------------+-----------------------+-------------------+----------------+
| Host      | User          | Select_priv | Insert_priv | Update_priv | Delete_priv | Create_priv | Drop_priv | Reload_priv | Shutdown_priv | Process_priv | File_priv | Grant_priv | References_priv | Index_priv | Alter_priv | Show_db_priv | Super_priv | Create_tmp_table_priv | Lock_tables_priv | Execute_priv | Repl_slave_priv | Repl_client_priv | Create_view_priv | Show_view_priv | Create_routine_priv | Alter_routine_priv | Create_user_priv | Event_priv | Trigger_priv | Create_tablespace_priv | ssl_type | ssl_cipher | x509_issuer | x509_subject | max_questions | max_updates | max_connections | max_user_connections | plugin                | authentication_string                     | password_expired | password_last_changed | password_lifetime | account_locked |
+-----------+---------------+-------------+-------------+-------------+-------------+-------------+-----------+-------------+---------------+--------------+-----------+------------+-----------------+------------+------------+--------------+------------+-----------------------+------------------+--------------+-----------------+------------------+------------------+----------------+---------------------+--------------------+------------------+------------+--------------+------------------------+----------+------------+-------------+--------------+---------------+-------------+-----------------+----------------------+-----------------------+-------------------------------------------+------------------+-----------------------+-------------------+----------------+
| localhost | root          | Y           | Y           | Y           | Y           | Y           | Y         | Y           | Y             | Y            | Y         | Y          | Y               | Y          | Y          | Y            | Y          | Y                     | Y                | Y            | Y               | Y                | Y                | Y              | Y                   | Y                  | Y                | Y          | Y            | Y                      |          
mysql> select host, user from user;
+-----------+---------------+
| host      | user          |
+-----------+---------------+
| localhost | mysql.session |
| localhost | mysql.sys     |
| localhost | root          |
+-----------+---------------+
3 rows in set (0.00 sec)

mysql> 
  • 将localhost修改为*
mysql> update user set host = '%' where user = 'root';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> select host, user from user;
+-----------+---------------+
| host      | user          |
+-----------+---------------+
| %         | root          |
| localhost | mysql.session |
| localhost | mysql.sys     |
+-----------+---------------+
3 rows in set (0.01 sec)

mysql> exit
Bye
  • 开启mysql端口 并查看所有打开的端口
[root@izm5e33l0ge76uqi8nq87az /]# 
[root@izm5e33l0ge76uqi8nq87az /]# systemctl start firewalld
[root@izm5e33l0ge76uqi8nq87az /]# firewall-cmd --zone=public --add-port=3306/tcp --permanent
success
[root@izm5e33l0ge76uqi8nq87az /]# firewall-cmd --reload
success
[root@izm5e33l0ge76uqi8nq87az /]# firewall-cmd --zone=public --list-ports
27017/tcp 9093/tcp 8000/tcp 5000/tcp 3306/tcp
[root@izm5e33l0ge76uqi8nq87az /]# systemctl restart mysqld
  • 记得配置完成之后,重启mysql
  • 然后就可以通过mysql客户端连接了
  • 卸载mysql
查询mysql安装包 rpm -qa | grep mysql*
rpm -e mysql*
或者yum remove -y mysql*




















你可能感兴趣的:(Linux下部署mysql)