linux下源码编译安装mysql

时间:2022-12-08 18:50:41

1.安装依赖的包:

yum install -y gdb cmake ncurses-devel bison bison-devel

2.创建mysql安装目录和数据文件目录

mkdir -p /usr/local/mysql
mkdir -p /usr/local/data

3.创建用户和组

groupadd mysql
useradd -r -g mysql mysql

4.编译安装

解压安装包 cd到解压目录

4.1 参数配置

cmake . \
-DCMAKE_INSTALL_PREFIX=/home/mysql \
-DMYSQL_DATADIR=/home/mysql/data \
-DSYSCONFDIR=/etc \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_MEMORY_STORAGE_ENGINE=1 \
-DWITH_READLINE=1 \
-DMYSQL_UNIX_ADDR=/home/mysql/mysql.sock \
-DMYSQL_TCP_PORT=3306 \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DEXTRA_CHARSETS=all \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DENABLE_DOWNLOADS=1

参数参考连接: http://dev.mysql.com/doc/refman/5.5/en/source-configuration-options.html

4.2 编译安装

make && make install

4.3 配置

##设置文件所有者
chown -R mysql mysql:mysql /usr/local/mysql

4.4 初始化配置

cd /usr/local/mysql/scripts
./mysql_install_db --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --user=mysql

4.5 设置环境变量

vi /etc/profile
PATH=$PATH:$HOME/bin:/usr/local/mysql/bin:/usr/local/mysql/lib
export PATH
. /etc/profile

*记得保存环境变量文件: . /etc/profile

5.其他

添加开机启动

cp support-files/mysql.server /etc/init.d/mysql
chkconfig mysql on
##启动命令
service mysql start

添加密码和远程启动

mysql -uroot
SET PASSWORD = PASSWORD('123456'); ##远程连接 username=用户名 自行设置 passowrd= 密码 %表示无论什么ip都可访问
也可以设置为某个用户特定ip才可访问,例如 'hbh'@'188.188.188.188' GRANT ALL PRIVILEGES ON *.* TO 'username'@'%' IDENTIFIED BY 'passowrd' WITH GRANT OPTION;