CentOS安装部署MySQL5.5.37过程[原创]
准备工作
1 2 3 4 5 6 7 8 9 |
rpm -qa|grep mysql rpm -e mysql yum -y remove mysql-server mysql mysql-libs yum -y remove php-mysql yum -y install yum-fastestmirror #关闭SELinux vi /etc/selinux/config #将SELINUX=enforcing改为SELINUX=disabled |
1 |
yum -y install bison gcc gcc-c++ autoconf automake zlib* libxml* ncurses-devel libtool-ltdl-devel* mysql-devel |
1 2 3 4 5 |
wget http://www.cmake.org/files/v2.8/cmake-2.8.12.2.tar.gz tar -zxvf cmake-2.8.12.2.tar.gz cd cmake-2.8.12.2 ./configure make && make install |
或者
#yum -y install cmake
下载补丁及安装包
1 2 3 4 5 6 |
#下载mysql-openssl.patch wget -c "http://bugs.mysql.com/file.php?id=19941&bug_id=68999" -O mysql-openssl.patch #或 wget -c http://soft.vpser.net/lnmp/ext/mysql-openssl.patch #下载mysql-5.5.37.tar.gz wget http://dev.mysql.com/get/Downloads/MySQL-5.5/mysql-5.5.37.tar.gz |
#打补丁
patch -p1 < ../mysql-openssl.patch
mkdir /data0/mysql/data
# cmake编译:( -DMYSQL_DATADIR=/data0/mysql/data 数据存储目录 )
1 |
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/data0/mysql/data -DEXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_FEDERATED_STORAGE_ENGINE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DWITH_PERFSCHEMA_STORAGE_ENGINE=1 -DMYSQL_UNIX_ADDR=/tmp/mysqld.sock -DMYSQL_TCP_PORT=3306 -DWITH_DEBUG=0 -DENABLED_LOCAL_INFILE=1 -DWITH_READLINE=1 -DWITH_SSL=system -DWITH_ZLIB=system -DWITH_EMBEDDED_SERVER=1 |
# 安装mysql
复制配置文件
#在support-files目录中有五个配置信息文件(这里很重要,一定要根据自己的内存复制对应的cnf文件,否则mysql始终起不来):
#my-small.cnf (内存<=64M)
#my-medium.cnf (内存 128M)
#my-large.cnf (内存 512M)
#my-huge.cnf (内存 1G-2G)
#my-innodb-heavy-4G.cnf (内存 4GB)
cd /usr/local/mysql
cp ./support-files/my-innodb-heavy-4G.cnf /etc/my.cnf
vi /etc/my.cnf
#在 [mysqld] 段增加或修改
datadir = /data0/mysql/data
wait-timeout = 30
default-storage-engine = MyISAM
max_connections = 512
max_allowed_packet = 16M
创建用户和组
设置权限
初始化数据库
1 |
/usr/local/mysql/scripts/mysql_install_db --defaults-file=/etc/my.cnf --basedir=/usr/local/mysql --datadir=/data0/mysql/data --user=mysql |
配置开机自启动
设置软连接
启动MySQL
设置mysql用户名和密码
/usr/local/mysql/bin/mysqladmin -u root password 123456
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
use mysql; #update user set password=password('123456') where user='root'; delete from user where not (user='root') ; delete from user where user='root' and password=''; show databases; drop database test; DROP USER ''@'%'; flush privileges; |
重启MySQL
测试MySQL是否启动
# 1)查看是否有进程mysql