Linux安装MYSQL(手工编译)
创建目录
mkdir mysql
创建用户
groupadd -r mysql
useradd -g mysql -r -M -s /sbin/nologin mysql
查看用户
id mysql
修改权限
chown -R mysql.mysql mysql
安装cmake
wget -c http://www.cmake.org/files/v2.8/cmake-2.8.3.tar.gz
tar -zxvf cmake-2.8.3.tar.gz
cd cmake-2.8.3
./bootstrap
./configure
make && make install
wget http://dev.mysql.com/Downloads/MySQL-5.5/mysql-5.5.27.tar.gz
tar xzvf mysql-5.5.27.tar.gz
cd mysql-5.5.27
cmake . \
-DCMAKE_INSTALL_PREFIX:PATH=/usr/local/mysql \
-DMYSQL_DATADIR=/lab/mysql_data \
-DMYSQL_UNIX_ADDR=/lab/mysql_data/mysql.sock \
-DMYSQL_TCP_PORT=3306 \
-DMYSQL_OPENSSL=/usr/local/ssl \
-DCURSES_LIBRARY=/usr/local/ncurses/lib/libncurses.so \
-DCURSES_INCLUDE_PATH=/usr/include \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_EXTRA_CHARSETS:STRING=utf8,gbk \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_READLINE=1 \
-DWITH_EMBEDDED_SERVER=1 \
-DWITH_SSL=bundled \
-DWITH_DUBUG=0 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 -LH
make && make install
中出现的问题
make[1]: *** No rule to make target '/usr/lib64/libncurses.so' ...'client/mysql' ... stop
查看了一下libncurses.so
[root@prod01 mysql-5.5.27]# find / -name libncurses.so
/usr/local/ncurses/lib/libncurses.so
/lab/re/ncurses-5.9/lib/libncurses.so
/lab/re/ncurses-5.6/lib/libncurses.so
对该参数做了修改
-DCURSES_LIBRARY=/usr/local/ncurses/lib/libncurses.so
重新cmake
然后make
最后make install
时间很长,且等着吧!
[100%] Built target my_safe_process
重新cmake的时候,需要删除一些文件
[root@prod01 mysql-5.5.27]# find /lab/re/ -name CMakeCache.txt
/lab/re/cmake-2.8.3/Tests/ComplexOneConfig/Cache/CMakeCache.txt
/lab/re/cmake-2.8.3/Tests/ComplexRelativePaths/Cache/CMakeCache.txt
/lab/re/cmake-2.8.3/Tests/Complex/Cache/CMakeCache.txt
/lab/re/cmake-2.8.3/Tests/CMakeFiles/CheckFortran/CMakeCache.txt
/lab/re/cmake-2.8.3/CMakeCache.txt
/lab/re/mysql-5.5.27/CMakeCache.txt
rm -f /lab/re/cmake-2.8.3/Tests/ComplexOneConfig/Cache/CMakeCache.txt
rm -f /lab/re/cmake-2.8.3/Tests/ComplexRelativePaths/Cache/CMakeCache.txt
rm -f /lab/re/cmake-2.8.3/Tests/Complex/Cache/CMakeCache.txt
rm -f /lab/re/cmake-2.8.3/Tests/CMakeFiles/CheckFortran/CMakeCache.txt
rm -f /lab/re/cmake-2.8.3/CMakeCache.txt
rm -f /lab/re/mysql-5.5.27/CMakeCache.txt
各项配置如下(东抄抄西抄抄):
cd /usr/local/mysql
复制默认全局启动参数配置文件到/etc目录
cp ./support-files/my-medium.cnf /etc/my.cnf
初始化授权表
执行下面的命令初始化授权表:
./scripts/mysql_install_db --user=mysql --datadir=/lab/mysql_data
更改mysql数据目录属主和权限
默认数据库文件保存目录为安装目录下的var目录,执行configure命令时可通过--localstatedir参数指定不同的目录
chown -R mysql.mysql /lab/mysql_data
执行下面的命令复制启动脚本到资源目录:
chmod -R 700 /lab/mysql_data
cp ./support-files/mysql.server /etc/rc.d/init.d/mysqld
执行下面的命令增加mysqld服务控制脚本执行权限:
chmod +x /etc/rc.d/init.d/mysqld
执行下面的命令将mysqld服务加入到系统服务:
chkconfig --add mysqld
执行下面的命令检查mysqld服务是否已经生效:
chkconfig --list mysqld
命令输出类似下面的结果:
mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off
表明mysqld服务已经生效,在2、3、4、5运行级别随系统启动而自动启动,以后可以使用service命令控制mysql的启动和停止。
usermod -s /bin/bash mysql
su mysql
启动mysqld服务:
service mysqld start
停止mysqld服务:
service mysqld stop
执行下面的命令关闭开机自启动:
chkconfig mysqld off
执行下面的命令可以改变开机自启动的运行级别为3、5:
chkconfig --level 35 mysqld on
将mysql的bin目录加入PATH环境变量
编辑/etc/profile文件:
vi /etc/profile
在文件最后添加如下两行:
PATH=$PATH:/usr/local/mysql/bin
export PATH
执行下面的命令使所做的更改生效:
source /etc/profile
发现问题Starting MySQL..The server quit without updating PID file
./scripts/mysql_install_db --user=mysql --datadir=/lab/mysql_data
解决客户端与服务器端的连接(mysql) :xxx.xxx.xxx.xxx is not allowed to connect to this mysql server
授权法
例如,你想myuser使用mypassword从任何主机连接到mysql服务器的话。
#su mysql
#mysql
GRANT ALL PRIVILEGES ON *.* TO ‘myuser’@'%’ IDENTIFIED BY ‘mypassword’ WITH GRANT OPTION;