mysql安装步骤(1)源码编译

一、准备文件

mysql-5.6.31.tar.gz
下载链接

二、编译

0、依赖

1
2
3
4
5
6
7
yum install -y glibc.i686
yum install -y gcc gcc-c++
yum install -y cmake
yum install -y ncurses-devel
yum install -y bison
yum install -y perl perl-devel
yum install -y autoconf

1、解压源码包mysql-5.6.31.tar.gz

1
$ tar -zxvf mysql-5.6.31.tar.gz

2、设置参数,这一步需要自定义mysql的安装路径

1
2
3
$ mkdir /home/sun_zeming/mysql/mysql-3
$ cd mysql-5.6.31/
$ cmake -DCMAKE_INSTALL_PREFIX=/home/sun_zeming/mysql/mysql-3 -DMYSQL_DATADIR=/home/sun_zeming/mysql/mysql-3/data -DSYSCONFDIR=/home/sun_zeming/mysql/mysql-3/conf -DMYSQL_UNIX_ADDR=/home/sun_zeming/mysql/mysql-3/mysql.sock -DMYSQL_TCP_PORT=6660 -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci

3、 编译

1
2
$ make
$ make install

三、MySQL安装

1、进入mysql的安装路径

1
$ cd /home/sun_zeming/mysql/mysql-3

2、复制默认配置文件

1
$ cp support-files/my-default.cnf ./my.cnf

3、修改配置文件my.cnf

1
2
3
4
5
basedir = /home/sun_zeming/mysql/mysql-3
datadir = /home/sun_zeming/mysql/mysql-3/data
port = 6660
# server_id = .....
socket = /home/sun_zeming/mysql/mysql-3/mysql.sock

4、安装mysql

1
$ ./scripts/mysql_install_db --user=root --defaults-file=/home/sun_zeming/mysql/mysql-3/my.cnf

四、启动MySQL

普通用户启动

1
./bin/mysqld --defaults-file=/home/sun_zeming/mysql/mysql-3/my.cnf

root用户启动

1
./bin/mysqld --defaults-file=/home/sun_zeming/mysql/mysql-3/my.cnf --user=root

五、MySQL授权

1、设置root用户密码

1
$ ./bin/mysqladmin -u root password "123456"

2、登录mysql

1
$ ./bin/mysql -uroot -p123456 -P6660

3、授权

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