Linux下离线安装MySql5.7全过程以及部分问题解决

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u012190514/article/details/80200771

系统:centOS6.8

数据库:mysql-5.7.12

 

过程不需要联网

1、下载安装包
http://dev.mysql.com/downloads/mysql/#downloads
推荐下载通用安装方法的TAR包(http://cdn.mysql.com//Downloads/MySQL-5.7/mysql-5.7.12-linux-glibc2.5-x86_64.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.开始解压,

[root@localhost ~]# tar xvf mysql-5.7.12-linux-glibc2.5-x86_64.tar

注意:解压命令不要带z, 即 tar -xvf mysql……tar,这个版本包含了两个版本,一个是32位版,一个是64位版

解压完后:这里是有.tar 的,

[root@localhost ~]# mysql-5.7.12-linux-glibc2.5-x86_64.tar.gz

再解压,得到我们想要的,并解压到/usr/local/apps/

apps是我前面创建的用户存放应用

[root@localhost ~]# tar -zxvf mysql-5.7.12-linux-glibc2.5-x86_64.tar.gz -C

/usr/local/apps/

 

这时在program下得到的目录名很长,如果不想改名,则可以建立一个连接(类似于Windows快捷方式):

[root@localhost apps]# ln -s mysql-5.7.12-linux-glibc2.5-x86_64 mysql

这么配置后,就可以用/usr/local/apps/mysql来找到mysql的安装目录了

注意,如果mysql目录下没有data目录,手动建一个。用户存放数据

初始化

[root@localhost ~]# /usr/local/apps/mysql/bin/mysqld --initialize --user=mysql --datadir=/usr/local/apps/mysql/data --basedir=/usr/local/apps/mysql

时间可能长了一点,稍微等下.

没有ERROR信息后进入下一步

5、设置mysql以服务运行并且开机启动

{mysql}/ support-files/mysql.server 拷贝为/etc/init.d/mysql并设置运行权限

{mysql}指的是/usr/local/apps/mysql路径,因人而异,后面用这个代替

#cp mysql.server /etc/init.d/mysql

#chmod +x /etc/init.d/mysql

 mysql注册为开机启动的服务

#chkconfig --add mysql

 当然也可以手动进行服务的开启和关闭:

#/etc/init.d/mysql start

#/etc/init.d/mysql stop

【添加本地配置】安装文件夹->本机

将mysql/support-files下的my-default.cnf改名为my.cnf,拷到/etc下      

[root@localhost ~]#cp /usr/local/apps/mysql/support-files/my-default.cnf   /etc/my.cnf

使用vim打开后编辑(以下仅为基础配置)

将三个都进行简单的配置可以解决不少bug,我前面踩了许多坑

[mysqld]

[mysql]

[client]

 

# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html
# *** DO NOT EDIT THIS FILE. It's a template which will be copied to the
# *** default location during install, and will be replaced if you
# *** upgrade to a newer version of MySQL.

[mysqld]
character-set-server = utf8
basedir = /usr/local/apps/mysql
datadir = /usr/local/apps/mysql/data
port = 3306
socket = /usr/local/apps/mysql/tmp/mysql.sock
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
 [client]
default-character-set=utf8
socket=/usr/local/apps/mysql/tmp/mysql.sock

[mysql]
default-character-set=utf8
socket=/usr/local/apps/mysql/tmp/mysql.sock
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M

# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin

# These are commonly set, remove the # and set as required.
# basedir = .....
# datadir = .....
# port = .....
# server_id = .....
# socket = .....

# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M

此外:socket =/usr/local/apps/mysql/tmp/mysql.sock,这里的tmp文件夹为自行创建

sock文件是用于建立两个程序之间的连接使用的。需要给与mysql用户(上文创建了)权限。

首先mkdirtmp,然后进入/usr/local/apps/mysql目录,修改权限

[root@localhost mysql]# chown -R mysql:mysql tmp

运行

#{mysql}/bin/mysqld_safe&

注:在这个启动脚本里已默认设置--user=mysql;在脚本末尾加&表示设置此进程为后台进程,区别就是在控制台输入bg,即可将当前进程转入后台,当前shell可进行其他操作。

 

客户端连接测试

[root@localhost mysql]#{mysql}/bin/mysql -uroot -p

我在登陆时时出现了这个错误(密码不正确):

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

解决方法:

打开my.cnf文件

[mysqld]下添加这么一行

skip-grant-tables

[mysqld]

character-set-server = utf8

basedir = /usr/local/apps/mysql

datadir = /usr/local/apps/mysql/data

port = 3306

socket = /usr/local/apps/mysql/tmp/mysql.sock

sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

skip-grant-tables

 

跳过密码校验,这样登陆mysql就不需要密码了

然后使用sql语句修改root用户的密码

update mysql.user set authentication_string=password('123456') where user='root' ;

然后,再将skip-grant-tables从my.cnf文件中去掉,即可完成。

重启mysql服务

再次运行

service mysql restart

[root@localhost mysql]#{mysql}/bin/mysql -uroot -p

就完成了 

最后还有一步,将MySQL加入环境变量

vim /etc/profile

#MySQL
export MYSQL_HOME=/usr/local/apps/mysql
export PATH=$PATH:$MYSQL_HOME/bin

添加在里面

然后 source /etc/profile

就可以在任意目录下使用 mysql -root -p 命令了

再授权所有其他主机都可访问

 

mysql>grant all on *.* to root@'%' identified by '123456'; 
mysql>flush privileges;

如果遇到ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement

解决方案:

 

安装完mysql 之后,登陆以后,不管运行任何命令,总是提示这个

step 1: SET PASSWORD = PASSWORD('your new password');

step 2: ALTER USER 'root'@'localhost' PASSWORD EXPIRE NEVER;

step 3: flush privileges;

 

特别感谢:

 

 https://www.linuxidc.com/Linux/2016-04/130414.htm

https://blog.csdn.net/u011531613/article/details/73612113

后记:

好久没上腾讯云,结果上去后发现一个新的错误.

在启动mysql服务时

[root@VM_0_13_centos ~]# service mysql start

打印报错。。 (xxx可能有所不同)

Starting MySQL...The server quit without updating PID file (/usr/local/mysql/data/xxxx.pid). [FAILED]

解决方案1:

重启服务器,直接命令输入 reboot

解决方案2:

参考下面网页

https://www.cnblogs.com/richiewlq/p/7521343.html

展开阅读全文

没有更多推荐了,返回首页