Ubuntu14.04编译安装mysql5.5
- 系统: Ubuntu14.04
- Mysql: mysql-5.5.54
- Mysql下载地址: https://cdn.mysql.com//Downloads/MySQL-5.5/mysql-5.5.54.tar.gz
1. 安装依赖
依赖库列表
- make
- cmake
- gcc, g++
- bison
- libncurses-dev
root@Apix:~> apt-get install make cmake g++ bison libncurses-dev
请确保以上依赖安装完成之后再执行以下步骤
2. 开始编译安装
1.添加mysql用户以及用户组
root@Apix:~> groupadd mysql
root@Apix:~> useradd -g mysql -s /sbin/nologin -M mysql
2.下载&&解压mysql5.5.54
root@Apix:~> wget https://cdn.mysql.com//Downloads/MySQL-5.5/mysql-5.5.54.tar.gz
root@Apix:~> tar zxvf mysql-5.5.54.tar.gz
root@Apix:~> cd mysql-5.5.54
3.目录设置(根据自己机器设置相应目录)
- mysql安装目录: /usr/local/mysql
- mysql数据目录: /usr/local/mysqldata/3306data
root@Apix:~/mysql-5.5.54> cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/usr/local/mysqldata/3306data -DWITH_INNOBASE_STORAGE_ENGINE=1 -DMYSQL_TCP_PORT=3306 -DMYSQL_UNIX_ADDR=/usr/local/mysql3306/data/mysql.sock -DWITH_DEBUG=0 -DMYSQL_USER=mysql
root@Apix:~/mysql-5.5.54>
root@Apix:~/mysql-5.5.54> make
root@Apix:~/mysql-5.5.54> make install
4.编译完成后, 安装数据库
root@Apix:~/mysql-5.5.54> cd /usr/local/mysql
root@Apix:/usr/local/mysql> chown -R mysql .
root@Apix:/usr/local/mysql> chgrp -R mysql .
# 初始化数据库
root@Apix:/usr/local/mysql> scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysqldata/3306data
root@Apix:/usr/local/mysql> chown -R root .
root@Apix:/usr/local/mysql> chown -R mysql /usr/local/mysqldata/3306data
5.复制配置文件到/etc目录下
root@Apix:/usr/local/mysql> cp support-files/my-medium.cnf /etc/my.cnf
6.启动Mysql
root@Apix:/usr/local/mysql> bin/mysqld_safe --user=mysql &
# 启动mysql,看是否成功
root@Apix:/usr/local/mysql> netstat -apn | grep 3306
7.设置root 密码:
此步骤需要在数据库启动之后才能执行成功
root@Apix:/usr/local/mysql> mysqladmin -u root password 'new-password'
8.配置自启动
# 将mysql的启动服务添加到系统服务中
root@Apix:/usr/local/mysql> cp support-files/mysql.server /etc/init.d/mysql
# 现在可以使用下面的命令启动mysql
root@Apix:/usr/local/mysql> service mysql start
root@Apix:/usr/local/mysql> service mysql stop
root@Apix:/usr/local/mysql> service mysql restart
9.为了让mysql各命令能正常使用 需设置环境变量(写入/etc/profile)
export PATH=/usr/local/mysql/bin:$PATH"
mysql5.5安装完成
作者 @Alex
2017 年 01月 19日