mysql的安装(Linux)

概览

1.安装mysql客户端
2.数据库字符集设置
3.启动mysql服务
4.测试mysql命令
5.设置root密码
6.设置mysql运行远程访问
7.设置开机自启
8.测试连接

如果是集群版的安装在你规划的需要安装mysql的虚拟机(服务器)上安装

1.安装mysql客户端

1.1 安装wget命令

1
yum -y install wget

1.2 下载mysql的repo源

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

1.3 安装

安装1.3.mysql-community-release-el7-5.noarch.rpm包

1
rpm -ivh mysql-community-release-el7-5.noarch.rpm

1.4 安装mysql客户端

1
2
3
yum install mysql-server

yun install mysql-devel

等待安装完毕

2.数据库字符集设置

配置mysql文件:

1
vim /etc/my.cnf

在最后添加配置参数

1
character-set-server=utf8

3.启动mysql服务

1
2
3
service mysqld start
或者
systemctl start mysqld

4.测试mysql命令

输入mysql命令

1
2
3
4
5
6
7
8
9
10
11
12
13
[root@master ~]# systemctl start mysqld
[root@master ~]# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.6.42 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.

5.设置root密码

1
2
3
4
5
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

设置密码

1
2
3
mysql> update user set authentication_string = password('root'), password_expired = 'N' where user = 'root';
Query OK, 4 rows affected (0.00 sec)
Rows matched: 4 Changed: 4 Warnings: 0

6.设置mysql运行远程访问

1
2
3
4
5
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'root' WITH GRANT OPTION;
Query OK, 0 rows affected (0.00 sec)

mysql> flush privileges; #刷新权限
Query OK, 0 rows affected (0.00 sec)

7.设置开机自启

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21

mysql> exit;
Bye
[root@master ~]# vim /etc/rc.local

#!/bin/bash
# THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES
#
# It is highly advisable to create own systemd services or udev rules
# to run scripts during boot instead of using this file.
#
# In contrast to previous versions due to parallel execution during boot
# this script will NOT be run after all other services.
#
# Please note that you must run 'chmod +x /etc/rc.d/rc.local' to ensure
# that this script will be executed during boot.

touch /var/lock/subsys/local
#追加内容
service mysqld start
~

8.测试连接

使用SQLyog或者Navicat工具测试连接,注意将防火墙关闭systemctl stop firewalld

在这里插入图片描述

测试连接成功则代表安装成功