002. Centos7安装mysql5.5.37

Posted 无止境

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了002. Centos7安装mysql5.5.37相关的知识,希望对你有一定的参考价值。

  1. 下载cmake-2.8.12.2.tar.gz, 下载地址: https://pan.baidu.com/s/1qYtpX7m
  2. 下载mysql-5.5.37.tar.gz, 下载地址: http://pan.baidu.com/s/1miFcNP2
  3. 下载ncurses-5.9.tar.gz, 下载地址: http://pan.baidu.com/s/1kVDIXW7

(百度网盘的连接地址使用wget下载不了)

4. 将上面三个包, 传到服务器上, 并解压

[[email protected] mysql-5.5.37]# tar xvf mysql-5.5.37.tar.gz

5. 进入cmake-2.8.12.2目录(如有报错请看文末)

[[email protected] cmake-2.8.12.2]# ./configure

[[email protected] cmake-2.8.12.2]# make && make install

6. 进入mysql-5.5.37目录

[[email protected] ~]# cd mysql-5.5.37

[[email protected] mysql-5.5.37]# cmake ./         (如有报错请看文末)

7. 解决完上面的报错后, 继续执行(如果没有报错, 此步骤可直接跳过)

[[email protected] ncurses-5.9]# cd ..

[[email protected] ~]# cd mysql-5.5.37

[[email protected] mysql-5.5.37]#

 [[email protected] mysql-5.5.37]# rm -f CMakeCache.txt 

因为刚才没有编译成功, 所以需要删除刚才编译生成的CmakeCache.txt文件, 否则过不去的, 然后重新cmake ./

[[email protected] mysql-5.5.37]# cmake ./

8.开始安装, mysql默认将成功安装到/usr/local/mysql

[[email protected] mysql-5.5.37]# make && make install

9. 在它安装的过程中创建一个mysql用户和mysql组

[[email protected] ~]# groupadd mysql

[[email protected] ~]# useradd -r -g mysql mysql

[[email protected] ~]# chown -R mysql.mysql /usr/local/mysql

这个目录,如果没有安装成功, 是不可以操作/usr/local/mysql目录的

10. 启动mysql

[[email protected] ~]# /usr/local/mysql/bin/mysqld_safe --user=mysql

11. 注册mysql服务, 设置开机自动启动

复制配置文件到etc下:

[[email protected] ~]# cp /usr/local/mysql/support-files/my-medium.cnf /etc/my.cnf

复制mysql启动文件到init.d目录下, 并命名为mysql

[root[email protected] ~]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql

[[email protected] ~]# chmod +x /etc/init.d/mysql

[[email protected] ~]# /sbin/chkconfig --add mysql

添加系统变量:

[[email protected] ~]# vi /etc/profile  #修改profile文件, 下次重启也能生效

export PATH=$PATH:/usr/local/mysql/bin # 在配置文件中加入此行配置

[[email protected] ~]# source /etc/profile

修改 .bashrc 文件使在当前用户 shell 下生效

# vi /root/.bashrc
在里面加入:

export PATH=$PATH:/usr/local/mysql/bin

修改这个文件之后同样也需要使用 source使配置文件生效.

启动mysql服务:

[[email protected] ~]# service mysql start  (可能会报错了)

Starting MySQL...The server quit without updating PID file [FAILED]cal/mysql/data/iZ25bdzgev8Z.pid).

//重新启动服务

[[email protected] ~]# /usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data

Installing MySQL system tables...

尝试连接:

[[email protected] ~]# /usr/local/mysql/bin/mysql -u root -p

12. 登录mysql

[[email protected] ~]# /usr/local/mysql/bin/mysql -u root -p

Enter password:

ERROR 2002 (HY000): Can‘t connect to local MySQL server through socket ‘/tmp/mysql.sock‘ (2) #没有mysql.sock文件

[[email protected] /]# killall mysqld              

[[email protected] /]# killall mysql                 #杀死所有和mysql相关的进程

[[email protected] ~]# ls /tmp/mysql

ls: cannot access /tmp/mysql: No such file or directory

[[email protected] ~]# find / -name mysql.sock            #找一找

/var/lib/mysql/mysql.sock

 修改my.cnf配置文件, 后重启mysql, 然后重新登录即可

[[email protected] ~]# vi /etc/my.cnf

                   [client]

#password       = your_password

port            = 3306

#socket         = /tmp/mysql.sock

socket         = /var/lib/mysql/mysql.sock   #如果这个不行, 还需要将上面一行给解开注释. . .

[[email protected] /]# netstat -tnulp | grep 3306       #过滤下3306, 此时应该没有任何信息

[[email protected] /]# /etc/rc.d/init.d/mysql start

Starting MySQL..                                           [  OK  ]

#此时再过滤3306应该有数据了

13. 使用mysql登录吧

[[email protected] /]# mysql

Welcome to the MariaDB monitor.  Commands end with ; or \g.

Your MySQL connection id is 1

Server version: 5.5.37-log Source distribution

Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others.

Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.

MySQL [(none)]> exit

Bye

 

 

 

错误及其解决方案:

1. 在安装cmake执行到, make时候报出以下错误:

e: *** No targets specified and no makefile found.  Stop.

解决方案:

这是没有安装编译环境所致, 联网安装gcc

yum install gcc gcc-c++ autoconf automake

 

2. 安装mysql 5.5.37时候的错误提示:

  Curses library not found.  Please install appropriate package,

      remove CMakeCache.txt and rerun cmake.On Debian/Ubuntu, package name is libncurses5-dev, on Redhat and derivates it is ncurses-devel.

Call Stack (most recent call first):

  cmake/readline.cmake:127 (FIND_CURSES)

  cmake/readline.cmake:217 (MYSQL_USE_BUNDLED_LIBEDIT)

  CMakeLists.txt:355 (MYSQL_CHECK_READLINE)

ncurses是字符终端下屏幕控制的基本库,很多新开发的程序已经不再使用,但要编译一些老的程序,还是会经常碰到,解决这个问题就是安装一下Curses即可

[[email protected] ~]# tar xvf ncurses-5.9.tar.gz

[[email protected] ~]# cd ncurses-5.9

[[email protected] ncurses-5.9]# ./configure && make && make install

 


以上是关于002. Centos7安装mysql5.5.37的主要内容,如果未能解决你的问题,请参考以下文章

centos7 mysql5.7安装

CentOS7 配置USB无线网卡驱动及wifi连接

centos7 中singularity的安装

002.centos7.3编译openjdk11

hadoop-3.0.0-beta1运维手册(002):安装Guest操作系统

Linux笔记(002) -- centos7 文档操作基本命令