centos7解压安装mysql_CentOS7安装mysql5.7解压缩版简明教程

本文实例讲述了CentOS7安装MysqL5.7解压缩版的方法。分享给大家供大家参考,具体如下:

1.下载安装包

2.检查库文件是否存在,如有删除。

[root@localhost Desktop]$ rpm -qa | grep MysqL

MysqL-libs-5.1.52-1.el6_0.1.x86_64

[root@localhost ~]$ rpm -e MysqL-libs-5.1.52.x86_64 --nodeps

[root@localhost ~]$

3.检查MysqL组和用户是否存在,如无创建。

[root@localhost ~]$ cat /etc/group | grep MysqL

MysqL:x:490:

[root@localhost ~]$ cat /etc/passwd | grep MysqL

MysqL:x:496:490::/home/MysqL:/bin/bash

以上为默认存在的情况,如无,执行添加命令:

[root@localhost ~]$groupadd MysqL

[root@localhost ~]$useradd -r -g MysqL MysqL

//useradd -r参数表示MysqL用户是系统用户,不可用于登录系统。

4.解压TAR包,更改所属的组和用户

[root@localhost ~]$ cd /usr/local/

[root@localhost local]$ tar xvf MysqL-5.7.12-linux-glibc2.5-x86_64.tar

[root@localhost local]$ ls -l

total 1306432

-rwxr--r--. 1 root root 668866560 Jun 1 15:07 MysqL-5.7.12-linux-glibc2.5-x86_64.tar

-rw-r--r--. 1 7161 wheel 638960236 Mar 28 12:54 MysqL-5.7.12-linux-glibc2.5-x86_64.tar.gz

-rw-r--r--. 1 7161 wheel 29903372 Mar 28 12:48 MysqL-test-5.7.12-linux-glibc2.5-x86_64.tar.gz

[root@localhost local]$ tar xvfz MysqL-5.7.12-linux-glibc2.5-x86_64.tar.gz

[root@localhost local]$ mv MysqL-5.7.12-linux-glibc2.5-x86_64 MysqL

[root@localhost local]$ ls -l

total 1306436

drwxr-xr-x. 2 root root 4096 Dec 4 2009 bin

drwxr-xr-x. 2 root root 4096 Dec 4 2009 etc

drwxr-xr-x. 2 root root 4096 Dec 4 2009 games

drwxr-xr-x. 2 root root 4096 Dec 4 2009 include

drwxr-xr-x. 2 root root 4096 Dec 4 2009 lib

drwxr-xr-x. 3 root root 4096 Dec 2 14:36 lib64

drwxr-xr-x. 2 root root 4096 Dec 4 2009 libexec

drwxr-xr-x. 9 7161 wheel 4096 Mar 28 12:51 MysqL

-rwxr--r--. 1 root root 668866560 Jun 1 15:07 MysqL-5.7.12-linux-glibc2.5-x86_64.tar

-rw-r--r--. 1 7161 wheel 638960236 Mar 28 12:54 MysqL-5.7.12-linux-glibc2.5-x86_64.tar.gz

-rw-r--r--. 1 7161 wheel 29903372 Mar 28 12:48 MysqL-test-5.7.12-linux-glibc2.5-x86_64.tar.gz

drwxr-xr-x. 2 root root 4096 Dec 4 2009 sbin

drwxr-xr-x. 6 root root 4096 Dec 2 14:36 share

drwxr-xr-x. 2 root root 4096 Dec 4 2009 src

[root@localhost local]$ chown -R MysqL MysqL/

[root@localhost local]$ chgrp -R MysqL MysqL/

[root@localhost local]$ cd MysqL/

5.安装和初始化数据库

[root@localhost MysqL]$ bin/MysqL_install_db --user=MysqL --basedir=/usr/local/MysqL/ --datadir=/usr/local/MysqL/data/

2016-06-01 15:23:25 [WARNING] MysqL_install_db is deprecated. Please consider switching to MysqLd --initialize

2016-06-01 15:23:30 [WARNING] The bootstrap log isn't empty:

2016-06-01 15:23:30 [WARNING] 2016-06-01T22:23:25.491840Z 0 [Warning] --bootstrap is deprecated. Please consider using --initialize instead

2016-06-01T22:23:25.492256Z 0 [Warning] Changed limits: max_open_files: 1024 (requested 5000)

2016-06-01T22:23:25.492260Z 0 [Warning] Changed limits: table_open_cache: 431 (requested 2000)

如果改变默认安装路径,则需要  1)/etc/my.cnf、/etc/init.d/MysqLd中修改  basedir='/apps/MysqL'  datadir='/apps/MysqL/data'  2)创建ln  mkdir -p /usr/local/MysqL/bin  ln -s /apps/MysqL/bin/MysqLd /usr/local/MysqL/bin/MysqLd

[root@localhost MysqL]$

[root@localhost MysqL]$ cp -a ./support-files/my-default.cnf /etc/my.cnf

[root@localhost MysqL]$ cp -a ./support-files/MysqL.server /etc/init.d/MysqLd

[root@localhost MysqL]$ cd bin/

[root@localhost bin]# ./MysqLd_safe --user=MysqL &

[1] 2932

[root@localhost bin]# 2016-06-01T22:27:09.708557Z MysqLd_safe Logging to '/usr/local/MysqL/data/localhost.localdomain.err'.

2016-06-01T22:27:09.854913Z MysqLd_safe Starting MysqLd daemon with databases from /usr/local/MysqL/data

[root@localhost bin]# /etc/init.d/MysqLd restart

Shutting down MysqL..2016-06-01T22:27:50.498694Z MysqLd_safe MysqLd from pid file /usr/local/MysqL/data/localhost.localdomain.pid ended

SUCCESS!

Starting MysqL. SUCCESS!

[1]+ Done ./MysqLd_safe --user=MysqL

[root@localhost bin]$

//设置开机启动

[root@localhost bin]$ chkconfig --level 35 MysqLd on

[root@localhost bin]$

6.初始化密码

MysqL5.7会生成一个初始化密码,而在之前的版本首次登陆不需要登录。

[root@localhost bin]$ cat /root/.MysqL_secret

# Password set for user 'root@localhost' at 2016-06-01 15:23:25,xxxxxR5H9

[root@localhost 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.12

Copyright (c) 2000,2016,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> SET PASSWORD = PASSWORD('123456');

Query OK,0 rows affected,1 warning (0.00 sec)

MysqL> flush privileges;

Query OK,0 rows affected (0.00 sec)

7.添加远程访问权限

MysqL> use MysqL;

Reading table information for completion of table and column names

You can turn off this feature to get a quicker startup with -A

Database changed

MysqL> update user set host = '%' where user = 'root';

Query OK,1 row affected (0.00 sec)

Rows matched: 1 Changed: 1 Warnings: 0

MysqL> select host,user from user;

+-----------+-----------+

| host | user |

+-----------+-----------+

| % | root |

| localhost | MysqL.sys |

+-----------+-----------+

//一定要重启才会生效。

/etc/init.d/MysqLd restart

遇到的问题:

找不到MysqL.sock,MysqL.sock丢失问题解决方法

连接MysqL时,机器上找不到MysqL.sock文件你可以简单地通过重启服务器重新创建得到它。因为服务器在启动时重新创建它。

[root@localhost MysqL-5.7.13]# ./bin/MysqL_install_db --user=MysqL

2016-06-26 02:47:09 [WARNING] MysqL_install_db is deprecated. Please consider switching to MysqLd --initialize

2016-06-26 02:47:09 [ERROR] The data directory needs to be specified.

MysqL,同时需要指定./support-files/MysqL.server中的basedir和datadir为相应路径)。

[root@localhost MysqL-5.7.13]# ./bin/MysqL_install_db --user=MysqL --basedir=/usr/local/MysqL-5.7.13/ --datadir=/usr/local/MysqL-5.7.13/data/

2016-06-26 02:48:47 [WARNING] MysqL_install_db is deprecated. Please consider switching to MysqLd --initialize

2016-06-26 02:49:19 [WARNING] The bootstrap log isn't empty:

2016-06-26 02:49:19 [WARNING] 2016-06-26T09:48:50.798592Z 0 [Warning] --bootstrap is deprecated. Please consider using --initialize instead

2016-06-26T09:48:50.898732Z 0 [Warning] Changed limits: max_open_files: 1024 (requested 5000)

2016-06-26T09:48:50.898778Z 0 [Warning] Changed limits: table_open_cache: 431 (requested 2000)

以上报错均因未在MysqL.server中指定自定义的路径。

若是还提示已经有data文件了 删除了它,新建即可

希望本文所述对大家CentOS服务器维护有所帮助。

总结

如果觉得编程之家网站内容还不错,欢迎将编程之家网站推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。

如您喜欢交流学习经验,点击链接加入交流1群:1065694478(已满)交流2群:163560250

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值