- 下载cmake-2.8.12.2.tar.gz, 下载地址: https://pan.baidu.com/s/1qYtpX7m
- 下载mysql-5.5.37.tar.gz, 下载地址: http://pan.baidu.com/s/1miFcNP2
- 下载ncurses-5.9.tar.gz, 下载地址: http://pan.baidu.com/s/1kVDIXW7
(百度网盘的连接地址使用wget下载不了)
4. 将上面三个包, 传到服务器上, 并解压
[root@iZ25bdzgev8Z mysql-5.5.37]# tar xvf mysql-5.5.37.tar.gz
5. 进入cmake-2.8.12.2目录(如有报错请看文末)
[root@iZ25bdzgev8Z cmake-2.8.12.2]# ./configure
[root@iZ25bdzgev8Z cmake-2.8.12.2]# make && make install
6. 进入mysql-5.5.37目录
[root@iZ25bdzgev8Z ~]# cd mysql-5.5.37
[root@iZ25bdzgev8Z mysql-5.5.37]# cmake ./ (如有报错请看文末)
7. 解决完上面的报错后, 继续执行(如果没有报错, 此步骤可直接跳过)
[root@iZ25bdzgev8Z ncurses-5.9]# cd ..
[root@iZ25bdzgev8Z ~]# cd mysql-5.5.37
[root@iZ25bdzgev8Z mysql-5.5.37]#
[root@iZ25bdzgev8Z mysql-5.5.37]# rm -f CMakeCache.txt
因为刚才没有编译成功, 所以需要删除刚才编译生成的CmakeCache.txt文件, 否则过不去的, 然后重新cmake ./
[root@iZ25bdzgev8Z mysql-5.5.37]# cmake ./
8.开始安装, mysql默认将成功安装到/usr/local/mysql
[root@iZ25bdzgev8Z mysql-5.5.37]# make && make install
9. 在它安装的过程中创建一个mysql用户和mysql组
[root@iZ25bdzgev8Z ~]# groupadd mysql
[root@iZ25bdzgev8Z ~]# useradd -r -g mysql mysql
[root@iZ25bdzgev8Z ~]# chown -R mysql.mysql /usr/local/mysql
这个目录,如果没有安装成功, 是不可以操作/usr/local/mysql目录的
10. 启动mysql
[root@iZ25bdzgev8Z ~]# /usr/local/mysql/bin/mysqld_safe --user=mysql
11. 注册mysql服务, 设置开机自动启动
复制配置文件到etc下:
[root@iZ25bdzgev8Z ~]# cp /usr/local/mysql/support-files/my-medium.cnf /etc/my.cnf
复制mysql启动文件到init.d目录下, 并命名为mysql
[root@iZ25bdzgev8Z ~]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
[root@iZ25bdzgev8Z ~]# chmod +x /etc/init.d/mysql
[root@iZ25bdzgev8Z ~]# /sbin/chkconfig --add mysql
添加系统变量:
[root@iZ25bdzgev8Z ~]# vi /etc/profile #修改profile文件, 下次重启也能生效
export PATH=$PATH:/usr/local/mysql/bin # 在配置文件中加入此行配置
[root@iZ25bdzgev8Z ~]# source /etc/profile
修改 .bashrc 文件使在当前用户 shell 下生效
# vi /root/.bashrc
在里面加入:
export PATH=$PATH:/usr/local/mysql/bin
修改这个文件之后同样也需要使用 source使配置文件生效.
启动mysql服务:
[root@iZ25bdzgev8Z ~]# service mysql start (可能会报错了)
Starting MySQL...The server quit without updating PID file [FAILED]cal/mysql/data/iZ25bdzgev8Z.pid).
//重新启动服务
[root@iZ25bdzgev8Z ~]# /usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
Installing MySQL system tables...
尝试连接:
[root@iZ25bdzgev8Z ~]# /usr/local/mysql/bin/mysql -u root -p
12. 登录mysql
[root@iZ25bdzgev8Z ~]# /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文件
[root@iZ25bdzgev8Z /]# killall mysqld
[root@iZ25bdzgev8Z /]# killall mysql #杀死所有和mysql相关的进程
[root@iZ25bdzgev8Z ~]# ls /tmp/mysql
ls: cannot access /tmp/mysql: No such file or directory
[root@iZ25bdzgev8Z ~]# find / -name mysql.sock #找一找
/var/lib/mysql/mysql.sock
修改my.cnf配置文件, 后重启mysql, 然后重新登录即可
[root@iZ25bdzgev8Z ~]# vi /etc/my.cnf
[client]
#password = your_password
port = 3306
#socket = /tmp/mysql.sock
socket = /var/lib/mysql/mysql.sock #如果这个不行, 还需要将上面一行给解开注释. . .
[root@iZ25bdzgev8Z /]# netstat -tnulp | grep 3306 #过滤下3306, 此时应该没有任何信息
[root@iZ25bdzgev8Z /]# /etc/rc.d/init.d/mysql start
Starting MySQL.. [ OK ]
#此时再过滤3306应该有数据了
13. 使用mysql登录吧
[root@iZ25bdzgev8Z /]# 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即可
[root@iZ25bdzgev8Z ~]# tar xvf ncurses-5.9.tar.gz
[root@iZ25bdzgev8Z ~]# cd ncurses-5.9
[root@iZ25bdzgev8Z ncurses-5.9]# ./configure && make && make install
3. 登录错误故障解决:
[root@iZ25bdzgev8Z ~]# mysql -u root -p
Enter password:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
[root@iZ25bdzgev8Z ~]# netstat -ano | grep 3306 #
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN off (0.00/0/0)
[root@iZ25bdzgev8Z ~]# mysql
Welcome to the MariaDB monitor. Commands end with ; or g.
Your MySQL connection id is 3
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)]> use mysql;
ERROR 1044 (42000): Access denied for user ''@'localhost' to database 'mysql'
#因为mysql数据库的user表里,存在用户名为空的账户即匿名账户,导致登录的时候是虽然用的是root,但实际是匿名登录的
MySQL [(none)]> exit
Bye
解决方案:
[root@iZ25bdzgev8Z ~]# service mysql stop #停止msyql
Shutting down MySQL. [ OK ]
[root@iZ25bdzgev8Z ~]# mysqld_safe --skip-grant-table
161228 09:23:52 mysqld_safe Logging to '/var/lib/mysql/iZ25bdzgev8Z.err'.
161228 09:23:52 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
#新开一个连接
[root@iZ25bdzgev8Z ~]# mysql -u root mysql
. . .
MariaDB [mysql]> delete from user where USER='';
Query OK, 0 rows affected (0.00 sec)
MariaDB [mysql]> show databases;
. . .
MariaDB [mysql]> flush privileges;
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> show databases;
. . .
MariaDB [(none)]> use mysql;
Database changed
MariaDB [mysql]> select host , user,password from user;
+-----------+------+-------------------------------------------+
| host | user | password |
+-----------+------+-------------------------------------------+
| localhost | root | *C722458C25A26EA653682196537D713A5AE439F8 |
| 127.0.0.1 | root | *C722458C25A26EA653682196537D713A5AE439F8 |
| ::1 | root | *C722458C25A26EA653682196537D713A5AE439F8 |
+-----------+------+-------------------------------------------+
3 rows in set (0.00 sec)