首页   >   代码编程

linux环境下mysql5.5二进制方式安装教程

在之前的文章中,我们讲过了如何在linux环境中使用二进制方式来安装mysql5.7,今天来讲一下mysql5.5的安装,大部分步骤都是一样的,只不过其中一些小的细节不一样。

mysql的版本越高,功能也越来越强大,但是随着而来的就是服务器开销增大,相信很多站长在建站初期,因为初期流量不会太大,所以购买的都是1G内存的云服务器,回想起我自己做的第一个网站,在mysql的版本选型上栽了一个很大的跟头,可以说简直是个深坑,差点儿没爬出来。

当时还不会在linux上安装mysql,请教了一个玩的好的dba哥们,他直接在博客上写了一个教程,我就参照这个教程来安装,因为他写博客的时候,用的是mysql5.6版本,我就也依葫芦画瓢安装了一个 mysql5.6,开始一切正常,后来却发现有点儿不对劲儿了,基本上每隔个三五天左右,网站就要崩一次,每次都是数据库连接不上的错误,开始以为是服务器被黑了,一番排查下来也没有发现中病毒的迹象,mysql的服务就这么莫名其妙的被关掉了,害得我每天都提心吊胆,每隔一会儿就要去检查一下服务器是否正常,说起来都是泪啊。

为了结束这种坑爹的日常,就开始各种请教各种查资料各种优化,可还是无济于事,但是又没办法,只能硬着头皮继续查资料,可能老天爷终于开眼了,在查资料的时候无意中看到有人提到过可能是服务器自己把mysql服务干掉了,瞬间醍醐灌顶,总算有了一个方向,顺着这个方向查资料,发现还真不是我一个人这样,而且在网上对于mysql5.6还有一个响亮的外号“内存小杀手”,对于1G内存的服务器,开一个mysql5.6,基本上内存就占了大半去了,所以在内存扛不住的时候,系统就会将内存占用最多mysql服务给kill掉了。

没办法,内存(钱)是硬伤,老老实实的将mysql版本切换到5.5,自此,再也没有出现过隔几天崩一次的情况了,当时心里那叫一个高兴,整个人跟中了五百万似的。

每一个步骤的详细描述,已经在 mysql5.7的安装 中讲过了,这里就不再重复了,直接上代码:

[root@jdu4e00u53f7 soft]# wget http://dev.mysql.com/get/Downloads/MySQL-5.5/mysql-5.5.57-linux-glibc2.12-x86_64.tar.gz
[root@jdu4e00u53f7 soft]# tar -zxvf mysql-5.5.57-linux-glibc2.12-x86_64.tar.gz
[root@jdu4e00u53f7 soft]# cd /usr/local/mysql/
[root@jdu4e00u53f7 mysql]# groupadd mysql
[root@jdu4e00u53f7 mysql]# useradd -r -g mysql mysql
[root@jdu4e00u53f7 mysql]# chown -R mysql:mysql /usr/local/mysql
[root@jdu4e00u53f7 mysql]# export PATH=/usr/local/mysql/bin:$PATH

上面的几个步骤一模一样,接下来这一个步骤就需要注意了,需要执行 mysql_install_db 来安装db文件,但是我们会发现,这个脚本在 scripts 目录下,而不是像mysql5.7一样在 bin 目录下面

linux环境下mysql5.5二进制方式安装教程

如上图,多了一个scripts文件夹,里面就只有一个mysql_install_db脚本,还有区别是data文件夹,在高版本mysql的二进制包中,是没有data文件夹的,执行了安装脚本之后会自动生成;而在低版本中是有的,不仅有,而且里面还有一个默认的test文件夹

[root@jdu4e00u53f7 mysql]# ./scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data/
Installing MySQL system tables...
/usr/local/mysql/bin/mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory

Installation of system tables failed!  Examine the logs in
/usr/local/mysql/data/ for more information.

You can try to start the mysqld daemon with:

    shell> /usr/local/mysql/bin/mysqld --skip-grant &

and use the command line tool /usr/local/mysql/bin/mysql
to connect to the mysql database and look at the grant tables:

    shell> /usr/local/mysql/bin/mysql -u root mysql
    mysql> show tables

Try 'mysqld --help' if you have problems with paths.  Using --log
gives you a log in /usr/local/mysql/data/ that may be helpful.

Please consult the MySQL manual section
'Problems running mysql_install_db', and the manual section that
describes problems on your OS.  Another information source are the
MySQL email archives available at http://lists.mysql.com/.

Please check all of the above before submitting a bug report
at http://bugs.mysql.com/

虽然错误信息格式不一样,但依旧是缺失libaio.so,还是一样,我们直接yum install一个

[root@jdu4e00u53f7 mysql]# yum install -y libaio

安装好了libaio之后,我们再来执行安装脚本,执行细节也和mysql5.7有很大差异

[root@jdu4e00u53f7 mysql]# ./scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data/
Installing MySQL system tables...
171012 12:03:34 [Note] Ignoring --secure-file-priv value as server is running with --bootstrap.
171012 12:03:34 [Note] /usr/local/mysql/bin/mysqld (mysqld 5.5.57) starting as process 3680 ...
OK
Filling help tables...
171012 12:03:34 [Note] Ignoring --secure-file-priv value as server is running with --bootstrap.
171012 12:03:34 [Note] /usr/local/mysql/bin/mysqld (mysqld 5.5.57) starting as process 3687 ...
OK

To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system

PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:

/usr/local/mysql/bin/mysqladmin -u root password 'new-password'
/usr/local/mysql/bin/mysqladmin -u root -h jdu4e00u53f7 password 'new-password'

Alternatively you can run:
/usr/local/mysql/bin/mysql_secure_installation

which will also give you the option of removing the test
databases and anonymous user created by default.  This is
strongly recommended for production servers.

See the manual for more instructions.

You can start the MySQL daemon with:
cd /usr/local/mysql ; /usr/local/mysql/bin/mysqld_safe &

You can test the MySQL daemon with mysql-test-run.pl
cd /usr/local/mysql/mysql-test ; perl mysql-test-run.pl

Please report any problems at http://bugs.mysql.com/

看上去没什么error,查看data文件夹,会发现多了很多系统文件

[root@jdu4e00u53f7 mysql]# ll data
total 28684
-rw-rw---- 1 mysql mysql 18874368 Oct 12 12:23 ibdata1
-rw-rw---- 1 mysql mysql  5242880 Oct 12 12:23 ib_logfile0
-rw-rw---- 1 mysql mysql  5242880 Oct 12 12:22 ib_logfile1
-rw-rw---- 1 mysql mysql     3492 Oct 12 12:23 jdu4e00u53f7.err
drwx------ 2 mysql mysql     4096 Oct 12 12:03 mysql
drwx------ 2 mysql mysql     4096 Oct 12 12:03 performance_schema
drwxr-xr-x 2 mysql mysql       20 Oct 12 11:44 test

按照官网的说法,install_db之后,会自动生成一个默认配置文件my.cnf,如果没有,就直接手动加一个,大家可以直接copy下面的内容

# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.5/en/server-configuration-defaults.html

[mysqld]

# 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 

sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES 

basedir = /usr/local/mysql
datadir = /usr/local/mysql/data

innodb_file_per_table = 1

#skip-grant-tables = 1

接下来的几个步骤也是一模一样

[root@jdu4e00u53f7 mysql]# cp my.cnf /etc/my.cnf
[root@jdu4e00u53f7 mysql]# ./support-files/mysql.server start
Starting MySQL.. SUCCESS! 
[root@jdu4e00u53f7 mysql]# ./support-files/mysql.server stop
Shutting down MySQL. SUCCESS! 
[root@jdu4e00u53f7 mysql]# cp support-files/mysql.server /etc/init.d/mysql
[root@jdu4e00u53f7 mysql]# service mysql start
Starting MySQL. SUCCESS! 
[root@jdu4e00u53f7 mysql]# service mysql stop
Shutting down MySQL.. SUCCESS!

总结下来,两个地方需要注意:

1、在mysql5.7版本中,安装db文件使用mysqld --initialize命令,而在mysql5.5中,安装db文件使用mysql_install_db命令;

2、在mysql5.7版本中,会为root生成一串随机密码,而在低版本中,root的默认密码为空。

QQ群: 686430774  /  718410762

站长Q: 1347384268

如果文章有帮到你,可以考虑请博主喝杯咖啡!

分享到:

欢迎分享本文,转载请注明出处!

作者:不忘初心

发布时间:2017-10-12

永久地址:https://www.jiweichengzhu.com/article/d3c5f1ccd5314fb6bca00a750e4eae24

评论