CentOS7安装mysql5.7.24

CentOS7安装mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz过程


问题描述:

百度搜索了半天,结果都是安着安着这那的毛病就出来了,终于安装好了,本人亲测有效,现在写下记录安装的过程。



提示:以下是本篇文章正文内容,下面案例可供参考

一、安装步骤

1:查看 linux下是否有老版本的mysql(有就删除)

查找old mysql:

rpm -qa  mysql| grep mysql

卸载:卸载命令:

rpm –ev {包名}——:rpm -ev mysql-community-common-5.7.23-1.el7.x86_64

查找老版本mysql相关的安装目录命令:find / -name mysql
若查找到相关目录使用命令:rm –rf {目录名}:删除目录

2:查看 linux 下是否安装 mariadb 数据库(有的话需要删除,因为有冲突)

检查是否安装了 mariadb:

rpm -qa maria* | grep maria*
我的是mariadb-libs-5.5.44-2.el7.centos.x86_64

删除mariadb:

rpm -e --nodeps mariadb-libs-5.5.52-1.el7.x86_64(强力删除)

3:创建mysql存放目录(/root/software)

创建文件夹:

mkdir /root/software

解压到当前文件夹,并把解压后文件移动到指定文件夹并修文件夹名称,

解压:tar -zxvf mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz
移动并修改名字:mv mysql-5.7.24-linux-glibc2.12-x86_64 /usr/local/mysql

4:主目录权限处理(查看是否有旧的用户,有删除并新建用户)

查看组和用户情况:

cat /etc/group | grep mysql

查看组和用户情况:

cat /etc/passwd |grep mysql

若存在,则删除原mysql用户:

userdel -r mysql  //会删除其对应的组和用户并在次查看。

创建mysql组:

groupadd mysql

创建mysql用户:

useradd -r -g mysql mysql

修改目录拥有者:

chown -R mysql:mysql /usr/local/mysql

5:创建配置文件及相关目录(如果在这个路径下已经存在的话就不用创建了)

创建配置文件:vi /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
# *** DO NOT EDIT THIS FILE. It‘s a template which will be copied to the
# *** default location during install, and will be replaced if you
# *** upgrade to a newer version of MySQL.
[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
# These are commonly set, remove the # and set as required.
 basedir = /usr/local/mysql
 datadir = /usr/local/mysql/data
 port = 3306
 server_id = 1
 socket = /tmp/mysql.sock
 pid-file=/tmp/mysqld/mysqld.pid
 character-set-server = utf8
 log-error=/var/log/mysqld.log
# 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
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

保存退出 :wq!(不要少了冒号)
创建文件/tmp/mysql.sock,设置用户组及用户,授权

cd /tmp
touch mysql.sock
chown mysql:mysql mysql.sock
chmod 755 mysql.sock

创建文件/tmp/mysqld/mysqld.pid

mkdir mysqld
cd mysqld
touch mysqld.pid
cd ..(两个.)
chown -R mysql:mysql mysqld
cd mysqld
chmod 755 mysqld.pid

创建文件/var/log/mysqld.log

touch /var/log/mysqld.log
chown -R mysql:mysql /var/log
cd /var/log
chmod 755 mysqld.log

6:安装和初始化数据库

进入初始化目录:cd /usr/local/mysql/bin/
初始化数据库:./mysqld --initialize --user=mysql --basedir=/usr/local/mysql--datadir=/usr/local/mysql/data
如果报错,(一般不会报错):(./mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory)
需要安装命令:yum -y install numactl
之后在执行初始化数据库:./mysqld --initialize --user=mysql --basedir=/usr/local/mysql--datadir=/usr/local/mysql/data

7:安全启动:

./mysqld_safe --user=mysql &

之后回车进入到bin目录
查看是否成功:

ps -ef | grep mysql

默认密码在mysqld.log日志里, 找到后保存到安全的地方:

cat /var/log/mysqld.log | grep root*
其中root@localhost: 后面的就是默认密码,后面登录用(D;J.ogLj8ETr)

进入bin目录:

cd /usr/local/mysql/bin/

登录mysql:

./mysql -u root -p

但是,若输入相关命令,则会提示你修改用户密码(注意后面一定要加)。
mysql> show databases; ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.

密码修改为 123456

mysql> set password=password("123456"); 

若出现这样

mysql> set password=password(123456);
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '“123456”)' at line 1
//出现这种情况的原因是MySQL5.6版本之前可以使用set password=password("123456");来设置密码,但我的是5.7版本,所以可以使用set password = '123456';

在这里插入图片描述

8:设置远程登录权限(在mysql里面设置)

mysql>grant all privileges on . to ‘root’@’%’ identified by ‘aaa’;
若出现这样的错误

mysql> grant all privileges on . to ‘root’@’%’ identified by ‘123456;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'to ‘root’@’%’ identified by ‘123456’' at line 1
请换这样使用
create user root@'%' identified by '123456';
grant all privileges on *.* to root@'%' with grant option;

刷新登录权限:

mysql> flush privileges;

退出quit 或者 exit

mysql> quit;

9:开机服务启动设置:

把support-files/mysql.server 拷贝为/etc/init.d/mysql
命令:

cp -a /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql

查看是否成功:(名字为mysql)

cd /etc/init.d/
ll

查看mysql服务是否在服务配置中

chkconfig --list mysql

若没有,则把mysql注册为开机启动的服务,然后在进行查看

[root@localhost init.d]# chkconfig --add mysql
[root@localhost init.d]# chkconfig --list mysql
注意:该输出结果只显示 SysV 服务,并不包含原生 systemd 服务。SysV 配置数据可能被原生 systemd 配置覆盖
      如果您想列出 systemd 服务,请执行 'systemctl list-unit-files'。
      欲查看对特定 target 启用的服务请执行    
      'systemctl list-dependencies [target]'。
mysql           0:1:2:3:4:5:6:

启动 或 停止

service mysql start
service mysql stop

10:创建快捷方式:

服务启动后,直接运行ysql -u root -p登录,不需要进入到对应的目录。

ln -s /usr/local/mysql/bin/mysql /usr/bin

11:使用Navicat 连接数据库时会出现(2003)

说明你的防火墙没有关。

解决方案:
/临时关闭 systemctl stop firewalld

//禁止开机启动
systemctl disable firewalld

二、连接步骤

查看虚拟机的IP地址

[root@localhost init.d]# ip add
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN 
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: eno16777736: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:da:b7:b6 brd ff:ff:ff:ff:ff:ff
    inet 192.168.17.104/24 brd 192.168.17.255 scope global eno16777736
       valid_lft forever preferred_lft forever
    inet6 fe80::20c:29ff:feda:b7b6/64 scope link 
       valid_lft forever preferred_lft forever
[root@localhost init.d]# 

打开navicat,直接连即可
在这里插入图片描述
在这里插入图片描述


总结

真的让人头大呀😝😱

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值