您好!欢迎来到雅安论坛
关注我们
扫码关注官方微信
手机版
手机扫描直接访问
欢迎: 附近的朋友。
111111

linux centos离线安装mysql5.7详细方法

[复制链接]
本站网友  发表于 2021-4-22 17:51:33 |阅读模式 打印 上一主题 下一主题
文章来源https://www.cnblogs.com/yy3b2007com/p/10497787.html感谢分享
centos7下使用mysql离线安装包安装mysql5.7
服务器环境:

centos7 x64

需要安装mysql5.7+

一、卸载CentOS7系统自带mariadb
  1. # 查看系统自带的Mariadb
  2. [root@CDH-141 ~]# rpm -qa|grep mariadb
  3. mariadb-libs-5.5.44-2.el7.centos.x86_64
  4. # 卸载系统自带的Mariadb
  5. [root@CDH-141 ~]# rpm -e --nodeps mariadb-libs-5.5.44-2.el7.centos.x86_64
  6. # 删除etc目录下的my.cnf
  7. [root@CDH-141 ~]# rm /etc/my.cnf
复制代码
二、检查mysql是否存在
  1. # 检查mysql是否存在
  2. [root@CDH-141 ~]# rpm -qa | grep mysql
  3. [root@CDH-141 ~]#
复制代码
三、查看用户和组是否存在1)检查mysql组合用户是否存在
  1. # 检查mysql组和用户是否存在,如无则创建
  2. [root@CDH-141 ~]# cat /etc/group | grep mysql
  3. [root@CDH-141 ~]# cat /etc/passwd | grep mysql
复制代码
# 查询全部用户(只是做记录,没必要执行)
  1. [root@CDH-141 ~]# cat /etc/passwd|grep -v nologin|grep -v halt|grep -v shutdown|awk -F ":" '{print $1 "|" $3 "1" $4}' | more
  2. root|010
  3. sync|510
  4. flume|9921989
  5. hdfs|9911988
  6. zookeeper|9891986
  7. llama|9881985
  8. httpfs|9871984
  9. mapred|9861983
  10. sqoop|9851982
  11. yarn|9841981
  12. kms|9831980
  13. hive|9821979
  14. oozie|9801977
  15. hbase|9781975
  16. impala|9761973
  17. hue|9741971
  18. wlaqzc2018|100111001
  19. [root@CDH-141 mysql]#
复制代码
2)若不存在,则创建mysql组和用户
  1. # 创建mysql用户组
  2. [root@CDH-141 ~]# groupadd mysql
  3. # 创建一个用户名为mysql的用户,并加入mysql用户组
  4. [root@CDH-141 ~]# useradd -g mysql mysql
  5. # 制定password 为111111
  6. [root@CDH-141 ~]# passwd mysql
  7. Changing password for user mysql.
  8. New password:
  9. BAD PASSWORD: The password is a palindrome
  10. Retype new password:
  11. passwd: all authentication tokens updated successfully.
复制代码
四、下载mysql离线安装包tar文件
官网下载地址:https://dev.mysql.com/downloads/mysql/5.7.html#downloads

版本选择,可以选择一下两种方式:

1)使用Red Hat Enterprise Linux
Select Version:5.7.25
Select Operating System:Red Hat Enterprise Linux / Oracle Linux
Select OS Version:Red Hat Enterprise Linux 7 / Oracle Linux 7 (x86, 64-bit)
列表中下载:
Compressed TAR Archive:(mysql-5.7.25-el7-x86_64.tar.gz)
2)使用Linux - Generic
Select Version:5.7.25
Select Operating Systeminux - Generic
Select OS Versioninux - Generic (glibc 2.12) (x86, 64-bit)
列表中下载:
Compressed TAR Archive:(mysql-5.7.25-linux-glibc2.12-x86_64.tar.gz)【本文中使用的是这个版本】
注意:上边两种方式找mysql离线安装包的方式都可以。

五、上传第四步下载的mysql TAR包
  1. # 进入/usr/local/文件夹
  2. [root@CDH-141 ~]# cd /usr/local/
  3. # 上传mysql TAR包
  4. [root@CDH-141 local]# rz
  5. # 解压mysql-5.7.25-linux-glibc2.12-x86_64.tar.gz
  6. [root@CDH-141 local]# ls
  7. bin  full-path-to-mysql-VERSION-OS  include  lib64    mysql-5.7.25-linux-glibc2.12-x86_64.tar.gz  share
  8. etc  games                          lib      libexec  sbin                                 src
  9. [root@CDH-141 local]# tar -zxvf mysql-5.7.25-linux-glibc2.12-x86_64.tar.gz
  10. mysql-5.7.25-lin
  11. ...
  12. mysql-5.7.25-linux-glibc2.12-x86_64/share/install_rewriter.sql
  13. mysql-5.7.25-linux-glibc2.12-x86_64/share/uninstall_rewriter.sql
  14. mysql-5.7.25-linux-glibc2.12-x86_64/support-files/magic
  15. mysql-5.7.25-linux-glibc2.12-x86_64/support-files/mysql.server
  16. mysql-5.7.25-linux-glibc2.12-x86_64/docs/INFO_BIN
  17. mysql-5.7.25-linux-glibc2.12-x86_64/docs/INFO_SRC
  18. [root@CDH-141 local]# ls
  19. bin  full-path-to-mysql-VERSION-OS  include  lib64    mysql-5.7.25-linux-glibc2.12-x86_64.tar.gz  share
  20. etc  games                          lib      libexec  mysql-5.7.25-linux-glibc2.12-x86_64  sbin                                        src
  21. # 进入/usr/local下,修改为mysql
  22. [root@CDH-141 local]# mv mysql-5.7.25-linux-glibc2.12-x86_64 mysql
  23. [root@CDH-141 local]# ls
  24. bin  etc  full-path-to-mysql-VERSION-OS  games  include  lib  lib64  libexec  mysql  mysql-5.7.25-linux-glibc2.12-x86_64.tar.gz  sbin  share  src
复制代码
六、更改所属的组和用户
  1. # 更改所属的组和用户
  2. [root@CDH-141 ~]# cd /usr/local/
  3. [root@CDH-141 local]# chown -R mysql mysql/
  4. [root@CDH-141 local]# chgrp -R mysql mysql/
  5. [root@CDH-141 local]# cd mysql/
  6. [root@CDH-141 mysql]# mkdir data
  7. [root@CDH-141 mysql]# chown -R mysql:mysql data
复制代码
七、在/etc下创建my.cnf文件
  1. # 进入/usr/local/mysql文件夹下
  2. [root@CDH-141 ~]# cd /usr/local/mysql
  3. # 创建my.cnf文件
  4. [root@CDH-141 mysql]# touch my.cnf #或者cd ''>my.conf
  5. # 编辑my.cnf
  6. [root@CDH-141 mysql]# vi my.conf
  7. [mysql]
  8. socket=/var/lib/mysql/mysql.sock
  9. # set mysql client default chararter
  10. default-character-set=utf8

  11. [mysqld]
  12. socket=/var/lib/mysql/mysql.sock
  13. # set mysql server port  
  14. port = 3323 #默认是3306,这里发现3306已经被占用,因此防止这种情况发生,可以避免使用3306mysql默认端口
  15. # set mysql install base dir
  16. basedir=/usr/local/mysql
  17. # set the data store dir
  18. datadir=/usr/local/mysql/data
  19. # set the number of allow max connnection
  20. max_connections=200
  21. # set server charactre default encoding
  22. character-set-server=utf8
  23. # the storage engine
  24. default-storage-engine=INNODB
  25. lower_case_table_names=1
  26. max_allowed_packet=16M
  27. explicit_defaults_for_timestamp=true

  28. [mysql.server]
  29. user=mysql
  30. basedir=/usr/local/mysql
  31. [root@CDH-141 mysql]#
复制代码
八、进入mysql文件夹,并安装mysql
  1. # 进入mysql
  2. [root@CDH-141 local]# cd /usr/local/mysql
  3. # 安装mysql
  4. [root@CDH-141 mysql]# bin/mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/
  5. 2019-03-08 18:11:07 [WARNING] mysql_install_db is deprecated. Please consider switching to mysqld --initialize
  6. 2019-03-08 18:11:24 [WARNING] The bootstrap log isn't empty:
  7. 2019-03-08 18:11:24 [WARNING] 2019-03-08T10:11:07.208602Z 0 [Warning] --bootstrap is deprecated. Please consider using --initialize instead
复制代码
设置文件及目录权限:
  1. [root@CDH-141 mysql]# cp ./support-files/mysql.server /etc/init.d/mysqld
  2. [root@CDH-141 mysql]# chown 777 my.cnf
  3. [root@CDH-141 mysql]# ls
  4. bin  COPYING  data  docs  include  lib  man  my.cnf  README  share  support-files
  5. [root@CDH-141 mysql]# ls -l
  6. total 60
  7. drwxr-xr-x  2 root  root   4096 Mar  8 15:56 bin
  8. -rw-r--r--  1  7161 31415 17987 Dec 21 18:39 COPYING
  9. drwxr-x---  5 mysql mysql  4096 Mar  8 16:21 data
  10. drwxr-xr-x  2 root  root   4096 Mar  8 15:56 docs
  11. drwxr-xr-x  3 root  root   4096 Mar  8 15:56 include
  12. drwxr-xr-x  5 root  root   4096 Mar  8 15:56 lib
  13. drwxr-xr-x  4 root  root   4096 Mar  8 15:56 man
  14. -rw-r--r--  1   777 root    516 Mar  8 16:19 my.cnf
  15. -rw-r--r--  1  7161 31415  2478 Dec 21 18:39 README
  16. drwxr-xr-x 28 root  root   4096 Mar  8 15:56 share
  17. drwxr-xr-x  2 root  root   4096 Mar  8 15:56 support-files
  18. [root@CDH-141 mysql]# chmod +x /etc/init.d/mysqld
  19. [root@CDH-141 mysql]#
  20. [root@CDH-141 mysql]# mkdir data
  21. [root@CDH-141 mysql]#
  22. [root@CDH-141 mysql]# chown -R mysql:mysql data
  23. [root@CDH-141 mysql]#
复制代码
九、启动mysql
  1. # 启动mysql
  2. [root@CDH-141 mysql]# /etc/init.d/mysqld restart
  3. MySQL server PID file could not be found![FAILED]
  4. Starting MySQL.Logging to '/usr/local/mysql/data/CDH-141.err'.
  5. ..The server quit without updating PID file (/usr/local/mysql/data/CDH-141.pid).[FAILED]
  6. [root@CDH-141 mysql]#
复制代码
出现错误,解决方案如下:
  1. #找到是否已经有进程占用
  2. [root@CDH-141 mysql]# ps aux|grep mysql
  3. root     32483  0.0  0.0 113252  1620 pts/0    S    18:04   0:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/usr/local/mysql/data --pid-file=/usr/local/mysql/data/CDH-141.pid
  4. mysql    32684  0.1  0.1 1119892 178224 pts/0  Sl   18:04   0:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=CDH-141.err --pid-file=/usr/local/mysql/data/CDH-141.pid --port=3323
  5. root     35137  0.0  0.0 112648   944 pts/0    S+   18:12   0:00 grep --color=auto mysql

  6. #关闭进程
  7. [root@CDH-141 mysql]# kill -9 32684
  8. [root@CDH-141 mysql]# /usr/local/mysql/bin/mysqld_safe: line 198: 32684 Killed                  nohup /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=CDH-141.err --pid-file=/usr/local/mysql/data/CDH-141.pid --port=3323 < /dev/null > /dev/null 2>&1
  9. #确认是否还占用
  10. [root@CDH-141 mysql]#  ps aux|grep mysql
  11. root     35501  0.0  0.0 112644   948 pts/0    S+   18:13   0:00 grep --color=auto mysql
  12. [root@CDH-141 mysql]# /etc/init.d/mysqld restart
  13. MySQL server PID file could not be found![FAILED]
  14. Starting MySQL..[  OK  ]
  15. [root@CDH-141 mysql]#

  16. # 重启mysql
  17. [root@CDH-141 mysql]# /etc/init.d/mysqld restart
  18. Shutting down MySQL..[  OK  ]
  19. Starting MySQL..[  OK  ]
  20. [root@CDH-141 mysql]#
复制代码
十、设置开机启动
  1. #设置开机启动
  2. [root@CDH-141 mysql]# chkconfig --level 35 mysqld on
  3. [root@CDH-141 mysql]# chkconfig --list mysqld

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

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

  10. mysqld          0:off   1:off   2:on    3:on    4:on    5:on    6:off
  11. [root@CDH-141 mysql]# chmod +x /etc/rc.d/init.d/mysqld
  12. [root@CDH-141 mysql]# chkconfig --add mysqld
  13. [root@CDH-141 mysql]# chkconfig --list mysqld

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

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

  20. mysqld          0:off   1:off   2:on    3:on    4:on    5:on    6:off
  21. [root@CDH-141 mysql]# service mysqld status
  22. MySQL running (26122)[  OK  ]
  23. [root@CDH-141 mysql]#
复制代码
十一、修改配置文件
  1. # 进入/etc/profile文件夹
  2. [root@CDH-141 mysql]# vim /etc/profile
  3. 修改/etc/profile,在最后添加如下内容
  4. # 修改/etc/profile文件
  5. #set mysql environment
  6. export PATH=$PATH:/usr/local/mysql/bin
  7. # 使文件生效
  8. [root@CDH-141 mysql]# source /etc/profile
复制代码
十二、获得mysql初始密码
1)获得mysql初始密码
  1. [root@CDH-141 mysql]#  cat /root/.mysql_secret  
  2. # Password set for user 'root@localhost' at 2019-03-08 17:40:42
  3. poc3u0mO_luv
  4. [root@CDH-141 mysql]#
复制代码
2)修改密码
  1. [root@CDH-141 mysql]# mysql -uroot -p
  2. Enter password: #此处填写上边获取到的初始密码‘poc3u0mO_luv’
  3. Welcome to the MySQL monitor.  Commands end with ; or \g.
  4. Your MySQL connection id is 2
  5. Server version: 5.7.25

  6. Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.
  7. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners.
  8. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

  9. mysql>  set PASSWORD = PASSWORD('123456');
  10. Query OK, 0 rows affected, 1 warning (0.00 sec)

  11. mysql> flush privileges;
  12. Query OK, 0 rows affected (0.00 sec)

  13. mysql> exit
  14. Bye
复制代码
3)验证新密码是否登录成功:
  1. [root@CDH-141 mysql]# mysql -uroot -p
  2. Enter password: #此处输入新密码‘123456’
  3. Welcome to the MySQL monitor.  Commands end with ; or \g.
  4. Your MySQL connection id is 4
  5. Server version: 5.7.25 MySQL Community Server (GPL)

  6. Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.
  7. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners.
  8. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

  9. mysql> show tables;
  10. ERROR 1046 (3D000): No database selected
  11. mysql> show databases;
  12. +--------------------+
  13. | Database           |
  14. +--------------------+
  15. | information_schema |
  16. | mysql              |
  17. | performance_schema |
  18. | sys                |
  19. +--------------------+
  20. 4 rows in set (0.00 sec)

  21. mysql>
复制代码
十三、添加远程访问权限
  1. # 添加远程访问权限
  2. mysql> use mysql
  3. Reading table information for completion of table and column names
  4. You can turn off this feature to get a quicker startup with -A

  5. Database changed
  6. mysql> update user set host='%' where user='root';
  7. Query OK, 1 row affected (0.00 sec)
  8. Rows matched: 1  Changed: 1  Warnings: 0

  9. mysql> select host,user from user;
  10. +-----------+---------------+
  11. | host      | user          |
  12. +-----------+---------------+
  13. | %         | root          |
  14. | localhost | mysql.session |
  15. | localhost | mysql.sys     |
  16. +-----------+---------------+
  17. 3 rows in set (0.00 sec)

  18. mysql>
复制代码
十四、重启mysql生效
  1. # 重启mysql
  2. [root@CDH-141 mysql]# /etc/init.d/mysqld restart
  3. Shutting down MySQL..[  OK  ]
  4. Starting MySQL..[  OK  ]
  5. [root@CDH-141 mysql]#
复制代码


回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

关注3

粉丝13

帖子2251

发布主题
阅读排行 更多
广告位
欢迎使用无需登录在线留言
姓名 

手机 

内容
关注我们
  • 关注官方微信

  • 论坛QQ群

Sitemap小黑屋Archiver雅安论坛( 已经安全运行 ) |网站地图

在线客服

会员收集的资源(插件源码等),仅方便学习,您需要自行承担版权风险,未获得原作者授权的情况下,请勿将文章公开发布或用于商业用途。

声明:本站内容来自于论坛作者本人的观点,不代表本网站的观点和看法,与本网站立场无关,相关责任作者自负。如有侵权,请联系我们及时删除

高能预警:本站为个人网站,非团队运作,常年务农,山上信号不好,在线少,如有不妥之处,望大佬们多多包涵,万分感激!

雅安论坛互联网违法和不良信息举报平台 您也可以通过留言进行相关问题提交,留言提交无需注册,我们将严格保证用户隐私。   © 2009-2021