centos7安装mysql5.7.24

编程入门 行业动态 更新时间:2024-10-11 17:28:36

centos7安装mysql5.7.24

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-defaultf 文件,我这边没有复制操作,直接编辑的 /etc 下面的myf文件(也可上传my-defaultf )

[root@localhost ~]# vi /etc/myf
[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 [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/myf.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.24Copyright (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 --listNote: This output shows SysV services only and does not include nativesystemd services. SysV configuration data might be overridden by nativesystemd 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 statusSUCCESS! MySQL running (1262)
[root@localhost ~]# 

参考博客:.html

更多推荐

centos7安装mysql5.7.24

本文发布于:2024-03-04 07:33:14,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1708633.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!