centos7 安装mysql

  • Post author:
  • Post category:mysql


linux系统是centos7.x.x版本,mysql5.7.x(这里介绍的是rpm安装方式,操作步骤较为简单,容易接受)

1.首先将系统自带的mariadb-lib卸载,不然后续安装时会报以下错误:

# error: mariadb-libs is obsoleted by mysql-community-libs-5.7.28-1.el7.x86_64

# error: Failed dependencies:

# error: libaio.so.1()(64bit) is needed by mysql-community-server-5.7.28-1.el7.x86_64

# error: libaio.so.1(LIBAIO_0.1)(64bit) is needed by mysql-community-server-5.7.28-1.el7.x86_64

# error: libaio.so.1(LIBAIO_0.4)(64bit) is needed by mysql-community-server-5.7.28-1.el7.x86_64

查看系统marialdb-lib版本,rpm -qa | grep -i mariadb(我服务器查到的是 mariadb-libs-5.5.52-1.el7.x86_64),然后执行卸载:rpm -e –nodeps mariadb-libs-5.5.52-1.el7.x86_64

2.安装最新的libaio

yum install libaio

yum install net-tools

3.下载并安装mysql

wget http://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.28-1.el7.x86_64.rpm-bundle.tar

tar -xvf mysql-5.7.28-1.el7.x86_64.rpm-bundle.tar

通常安装下面这四个文件即可

rpm -ivh mysql-community-common-5.7.28-1.el7.x86_64.rpm

rpm -ivh mysql-community-libs-5.7.28-1.el7.x86_64.rpm

rpm -ivh mysql-community-client-5.7.28-1.el7.x86_64.rpm

rpm -ivh mysql-community-server-5.7.28-1.el7.x86_64.rpm

如果出现以下错误(需安装:yum install numactl),或是安装以上包时追加  –nodeps –force(rpm -ivh mysql-community-common-5.7.28-1.el7.x86_64.rpm  –nodeps –force):

warning: mysql-community-server-5.7.28-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY

error: Failed dependencies:

libnuma.so.1()(64bit) is needed by mysql-community-server-5.7.28-1.el7.x86_64

libnuma.so.1(libnuma_1.1)(64bit) is needed by mysql-community-server-5.7.28-1.el7.x86_64

libnuma.so.1(libnuma_1.2)(64bit) is needed by mysql-community-server-5.7.28-1.el7.x86_64

4. 初始化

为了保证数据库目录为与文件的所有者为 mysql 登陆用户,如果你的linux系统是以 root 身份运行 mysql 服务,需要执行下面的命令初始化

mysqld –initialize –user=mysql

my.cnf/my.ini 支持Emoji表情

character-set-server=utf8mb4

collation_server=utf8mb4_unicode_ci

cat /var/log/mysqld.log | grep password(查看初始密码),找到 “root@localhost:xxx”

5.启动,修改默认密码

启动:

systemctl start mysqld

或 service mysqld start

停止:

service mysqld stop

重启:

service mysqld restart

连接mysql

mysql -u root -p

修改密码(不然后续操作会提示请更换密码)

set password = password[‘xxx’]  // xxx处替换为你要设置的新密码,看好,说的是只替换xxx

6. 仅上述操作,只能当前服务器内登录连接,相信你肯定是要外部开发调试连接的,那么,下一条命令是配置外部访问权限:

grant all privileges on *.* to ‘root’ @’%’ identified by ‘xxx’;  // xxx处替换为外部访问密码,可区别于本地密码,方便后期管理,

flush privileges;

如果转载,请注明出处:

https://blog.csdn.net/hz_hero/article/details/81157024



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