centos7安装mysql5.7.24

工具:secureCRT

1、用secureCRT连接linux虚拟机,通过sftp上传mysql5.7.24压缩包到linux的/root文件夹下。

[root@localhost local]# cd /root
[root@localhost ~]# ls
anaconda-ks.cfg  mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz

2、将mysql压缩包解压至 /usr/local 文件夹下,将其改名为mysql。

 

[root@localhost ~]# cd /usr/local
[root@localhost local]# tar -zxvf /root/mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz
[root@localhost local]# ls
bin  etc  games  include  lib  lib64  libexec  mysql-5.7.24-linux-glibc2.12-x86_64 sbin share  src
[root@localhost local]# mv mysql-5.7.24-linux-glibc2.12-x86_64 mysql
[root@localhost local]# ls
bin  etc  games  include  lib  lib64  libexec  mysql  sbin  share  src

 

3、进入mysql,由于5.7没有data目录,自己创建一个

[root@localhost mysql]# mkdir data
[root@localhost mysql]# ls
bin  COPYING  data  docs  include  lib  man  README  share  support-files


4、创建mysql用户和用户组

[root@localhost mysql]# groupadd mysql
[root@localhost mysql]# useradd -r -s /sbin/nologin -g mysql mysql -d /usr/local/mysql 
#useradd -r参数表示mysql用户是系统用户,不可用于登录系统

5、改变mysql目录权限,之前是root权限,现在设置成mysql权限

[root@localhost mysql]# chown -R mysql.mysql /usr/local/mysql/

    

6、初始化数据库

[root@localhost mysql]# ./bin/mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/
2018-11-15 21:45:51 [WARNING] mysql_install_db is deprecated. Please consider switching to mysqld --initialize
2018-11-15 21:45:54 [WARNING] The bootstrap log isn't empty:
2018-11-15 21:45:54 [WARNING] 2018-11-15T13:45:51.980331Z 0 [Warning] --bootstrap is deprecated. Please consider using --initialize instead
2018-11-15T13:45:51.981208Z 0 [Warning] Changed limits: max_open_files: 1024 (requested 5000)
2018-11-15T13:45:51.981219Z 0 [Warning] Changed limits: table_open_cache: 431 (requested 2000)

7、把mysql放到本地系统服务中

[root@localhost mysql]#  cp -a ./support-files/mysql.server /etc/init.d/mysqld

8、由于mysql内没有my-default.cnf 文件,我这边没有复制操作,直接编辑的 /etc 下面的my.cnf文件(也可上传my-default.cnf )

[root@localhost ~]# vi /etc/my.cnf
[mysqld]
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
socket=/tmp/mysql.sock
user=mysql
port=3306
character-set-server=utf8
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemd

#[mysqld_safe]
#log-error=/var/log/mariadb/mariadb.log
#pid-file=/var/run/mariadb/mariadb.pid

#
# include all files from the config directory
#
!includedir /etc/my.cnf.d

注意:mysql连接localhost通常通过一个Unix域套接字文件进行,一般是/tmp/mysql.sock,这个socket路径不要修改,不然连本地mysql的时候回报错:ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

9、尝试启动mysql服务

[root@localhost ~]# service mysqld start
Starting MySQL.Logging to '/usr/local/mysql/data/localhost.localdomain.err'.
 SUCCESS! 

10、查看初始密码,尝试登陆mysql

[root@localhost mysql]#  cat /root/.mysql_secret 
# Password set for user 'root@localhost' at 2018-11-14 23:33:33 
?G5W&tz1z.cN

[root@localhost mysql]# bin/mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.24

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.

mysql> 

11、登陆成功,修改密码

mysql> SET PASSWORD FOR 'root'@localhost=PASSWORD('123456');
Query OK, 0 rows affected, 1 warning (0.01 sec)

12、配置mysql环境变量,修改/etc/profile文件,在最下方添加配置,加入开机自启。

[root@localhost ~]# vi /etc/profile

export PATH=$PATH:/usr/local/mysql/bin

然后让其立即生效

[root@localhost ~]# source /etc/profile
[root@localhost ~]# mysql -uroot -p
Enter password: 

开机自启配置

[root@localhost ~]# chmod +x /etc/init.d/mysqld
[root@localhost ~]# chkconfig --add mysqld
[root@localhost ~]# chkconfig --list

Note: This output shows SysV services only and does not include native
      systemd services. SysV configuration data might be overridden by native
      systemd configuration.

      If you want to list systemd services use 'systemctl list-unit-files'.
      To see services enabled on particular target use
      'systemctl list-dependencies [target]'.

mysqld          0:off   1:off   2:on    3:on    4:on    5:on    6:off
netconsole      0:off   1:off   2:off   3:off   4:off   5:off   6:off
network         0:off   1:off   2:on    3:on    4:on    5:on    6:off

如果看到mysql的服务,并且3,4,5都是on的话则成功,如果是off,则键入

chkconfig --level 345 mysqld on

然后重启电脑

[root@localhost ~]# reboot

查看mysql运行状态

[root@localhost ~]# service mysqld status
 SUCCESS! MySQL running (1262)
[root@localhost ~]# 

参考博客:https://www.cnblogs.com/oldAlcazar/p/6835573.html

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值