yum update升级以后的系统版本为
[root@mysql ~]# cat /etc/redhat-release
CentOS Linux release 7.9.2009 (Core)
由于CentOS 7 版本将MySQL数据库软件从默认的程序列表中移除,所以之前的
#yum install mysql
#yum install mysql-server
#yum install mysql-devel
可能安装会出现各种意想不到的问题,我们用其他的方式来安装
首先从官网下载安装mysql-server
# wget http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm
# rpm -ivh mysql-community-release-el7-5.noarch.rpm
# yum install mysql-community-server
安装成功后重启mysql服务
# service mysqld restart
初次安装mysql,root账户没有密码
[root@mysql ~]# mysql -u root
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 7
Server version: 5.6.51 MySQL Community Server (GPL)
Copyright (c) 2000, 2021, 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> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
+--------------------+
4 rows in set (0.00 sec)
mysql>
这里范例设置root密码为123456,自己根据需求修改
mysql> set password for 'root'@'localhost' =password('123456');
Query OK, 0 rows affected (0.00 sec)
mysql>
退出后即可生效,无须重启
到此,数据库安装完成
1、编码
mysql配置文件为/etc/my.cnf,
vim /etc/my.cnf
在此文件的最后加上编码配置
[mysql]
default-character-set =utf8
这里的字符编码必须和/usr/share/mysql/charsets/Index.xml中一致
下面附的是需要对照的代码片段
[root@mysql ~]# cat /usr/share/mysql/charsets/Index.xml
.......
<charset name="utf8">
<family>Unicode</family>
<description>UTF-8 Unicode</description>
<alias>utf-8</alias>
<collation name="utf8_general_ci" id="33">
<flag>primary</flag>
<flag>compiled</flag>
</collation>
<collation name="utf8_bin" id="83">
<flag>binary</flag>
<flag>compiled</flag>
</collation>
</charset>
.......
2、远程连接设置
把在所有数据库的所有表的所有权限赋值给位于所有IP地址的root用户,也就是开放root账户给外网,一般不建议这么做
mysql> grant all privileges on *.* to root@'%'identified by 'password';
建议添加新用户,然后赋权远程访问
这里我举例新建一个名称为frimray密码为123456的用户并赋予远程访问
mysql>create user 'frimray'@'%' identified by '123456';
执行完毕,exit退出
此时远程连接已经配置完成
3、修改端口号
进入mysql数据库,输入show global variables like 'port';
查看端口号
mysql> show global variables like 'port';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| port | 3306 |
+---------------+-------+
1 row in set (0.00 sec)
这里可以看出目前本机mysql端口号为3306
修改端口,编辑文件/etc/my.conf
vim /etc/my.conf
在下面位置添加端口参数【这里以将端口修改为21023为例】:
port=21023
这是文件需要添加的位置
[root@mysql ~]# vim /etc/my.cnf
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html
[mysqld]
port=21023
#
# 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
然后重启数据库
systemctl restart mysqld.service
注:重启过程基本持续时间也就2-5秒左右,如果长时间无反应,可能是由于开启了selinux,那么你需要执行以下代码,关闭selinux,然后再重启即可
/usr/sbin/setenforce 0
启动完成后,开放该端口
firewall-cmd --zone=public --add-port=21023/tcp --permanent
firewall-cmd --reload
确认下端口号是否开启
firewall-cmd --query-port=21023/tcp
输出结果为yes即为开启成功
然后就可以在外部登录MySQL了。
全文结束