linux安装mysql解压版_CentOS7安装mysql5.7解压缩版简明教程

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

1.下载安装包

推荐下载通用安装方法的tar包

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.

解决:需要新建data目录,指定安装目录(在非默认目录时需要指定,默认路径:/usr/local/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服务器维护有所帮助。

如您对本文有疑问或者有任何想说的,请点击进行留言回复,万千网友为您解惑!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值