CentOS 6.5安装MySQL_5.5.43
时间:2016-04-02 03:32 来源:linux.it.net.cn 作者:IT
1.安装依赖包和开发工具:
yum install vim vim-enhanced wget zip unzip telnet ntsysv compat* apr* nasm* gcc gcc* gcc-c++ ntp make imake cmake automake autoconf zlib zlib-devel glibc glibc-devel glib2 libxml glib2-devel libxml2 libxml2-devel bzip2 bzip2-devel libXpm libXpm-devel libidn libidn-devel libtool libtool-ltdl-devel* libmcrypt libmcrypt-devel libevent-devel libmcrypt* curl curl-devel perl perl-Net-SSLeay pcre pcre-devel ncurses ncurses-devel openssl openssl-devel openldap openldap-devel openldap-clients openldap-servers krb5 krb5-devel e2fsprogs e2fsprogs-devel libjpeg libpng libjpeg-devel libjpeg-6b libjpeg-devel-6b libpng-devel libtiff-devel freetype freetype-devel fontconfig-devel gd gd-devel kernel screen sysstat flex bison nss_ldap pam-devel compat-libstdc++-33
2.清除系统中mysql痕迹:
yum remove mysql
rm -f /etc/my.cnf
3.创建mysql用户和用户组:
groupadd mysql
useradd -s /sbin/nologin -M -g mysql mysql
4.解压、配置、编译、安装mysql:
tar zxvf mysql-5.5.43.tar.gz -C /usr/src
cd /usr/src/mysql-5.5.43
cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_DATADIR=/home/mysql/data \
-DEXTRA_CHARSETS=all \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_READLINE=1 \
-DWITH_SSL=system \
-DWITH_ZLIB=system \
-DWITH_EMBEDDED_SERVER=1 \
-DENABLED_LOCAL_INFILE=1
make && make install
5.cp /usr/src/mysql-5.5.43/support-files/my-medium.cnf /etc/my.cnf
vim /etc/my.cnf
[client]
port = 3306
socket = /tmp/mysqld.sock
[mysqld]
port = 3306
socket = /tmp/mysqld.sock
datadir = /home/mysql/data
skip-name-resolve
skip-external-locking
key_buffer_size = 384M
max_allowed_packet = 16M
table_open_cache = 512
sort_buffer_size = 2M
read_buffer_size = 2M
read_rnd_buffer_size = 8M
myisam_sort_buffer_size = 64M
thread_cache_size = 8
query_cache_size = 32M
thread_concurrency = 8
datadir = /home/mysql/data
wait-timeout = 600
max_connections = 512
max_connect_errors = 10000000
local-infile=0
server-id = 1
log-bin = /home/mysql/log/mysql-bin
[mysqldump]
quick
max_allowed_packet = 16M
[mysqld_safe]
log-error = /home/mysql/log/mysql_error.log
log_slow_queries = /home/mysql/log/slowquery.log
long_query_time = 3
[mysql]
no-auto-rehash
[myisamchk]
key_buffer_size = 256M
sort_buffer_size = 256M
read_buffer = 2M
write_buffer = 2M
[mysqlhotcopy]
interactive-timeout
6.创建目录并修改权限:
mkdir -p /home/mysql/log
mkdir -p /home/mysql/data
chown -R mysql:mysql /home/mysql/date
chown -R mysql:mysql /home/mysql/log
chown -R mysql:mysql /usr/local/mysql
7.生成新的mysql授权表:
/usr/local/mysql/scripts/mysql_install_db --defaults-file=/etc/my.cnf --basedir=/usr/local/mysql --datadir=/home/mysql/data --user=mysql
8.添加mysqld系统服务:
cp /usr/src/mysql-5.5.43/support-files/mysql.server /etc/init.d/mysqld
chmod +x /etc/init.d/mysqld
chkconfig --add mysqld
chkconfig --level 2345 mysqld on
chkconfig --list | grep mysqld
9.添加加载mysql库文件的路径:
cat>/etc/ld.so.conf.d/mysql-x86_64.conf<<EOF
/usr/local/mysql/lib
/usr/lib64/mysql
EOF
cp /etc/ld.so.conf.d/mysql-x86_64.conf /etc/ld.so.conf.d/mysql.conf
ldconfig
10.链接mysql可执行文件:
ln -s /usr/local/mysql/lib/mysql /usr/lib64/mysql
ln -s /usr/local/mysql/include/mysql /usr/include/mysql
ln -s /usr/local/mysql/bin/mysql /usr/bin/mysql
ln -s /usr/local/mysql/bin/mysqldump /usr/bin/mysqldump
ln -s /usr/local/mysql/bin/myisamchk /usr/bin/myisamchk
ln -s /usr/local/mysql/bin/mysqld_safe /usr/bin/mysqld_safe
ln -s /usr/local/mysql/bin/mysqladmin /usr/bin/mysqladmin
11.启动mysql服务:
service mysqld start
ps -aux | grep mysqld
netstat -anptu | grep :3306
12.登录并修改mysql的root密码:
mysql -uroot -p
(第一次登录root密码为空)
use mysql;
update user set password=PASSWORD('root') where user='root';
delete from user where not (user='root');
delete from user where user='root' and password='';
delete from user where Host='localhost.localdomain';
delete from user where Host='::1';
grant all privileges on *.* to root@"%" identified by "root";
update mysql.user set Grant_priv='Y' where Host='%';
flush privileges;
13.刷新MySQL连接主机数量:
mysqladmin -uroot -p flush-hosts
#输入mysql的root帐号新密码
14.防火墙开启3306端口:
iptables -A INPUT -p tcp --dport 3306 -j ACCEPT
(责任编辑:IT)
1.安装依赖包和开发工具: yum install vim vim-enhanced wget zip unzip telnet ntsysv compat* apr* nasm* gcc gcc* gcc-c++ ntp make imake cmake automake autoconf zlib zlib-devel glibc glibc-devel glib2 libxml glib2-devel libxml2 libxml2-devel bzip2 bzip2-devel libXpm libXpm-devel libidn libidn-devel libtool libtool-ltdl-devel* libmcrypt libmcrypt-devel libevent-devel libmcrypt* curl curl-devel perl perl-Net-SSLeay pcre pcre-devel ncurses ncurses-devel openssl openssl-devel openldap openldap-devel openldap-clients openldap-servers krb5 krb5-devel e2fsprogs e2fsprogs-devel libjpeg libpng libjpeg-devel libjpeg-6b libjpeg-devel-6b libpng-devel libtiff-devel freetype freetype-devel fontconfig-devel gd gd-devel kernel screen sysstat flex bison nss_ldap pam-devel compat-libstdc++-33 2.清除系统中mysql痕迹: yum remove mysql rm -f /etc/my.cnf 3.创建mysql用户和用户组: groupadd mysql useradd -s /sbin/nologin -M -g mysql mysql 4.解压、配置、编译、安装mysql: tar zxvf mysql-5.5.43.tar.gz -C /usr/src cd /usr/src/mysql-5.5.43 cmake \ -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \ -DMYSQL_DATADIR=/home/mysql/data \ -DEXTRA_CHARSETS=all \ -DDEFAULT_CHARSET=utf8 \ -DDEFAULT_COLLATION=utf8_general_ci \ -DWITH_READLINE=1 \ -DWITH_SSL=system \ -DWITH_ZLIB=system \ -DWITH_EMBEDDED_SERVER=1 \ -DENABLED_LOCAL_INFILE=1 make && make install 5.cp /usr/src/mysql-5.5.43/support-files/my-medium.cnf /etc/my.cnf vim /etc/my.cnf [client] port socket [mysqld] port socket datadir = /home/mysql/data skip-name-resolve skip-external-locking key_buffer_size = 384M max_allowed_packet = 16M table_open_cache = 512 sort_buffer_size = 2M read_buffer_size = 2M read_rnd_buffer_size = 8M myisam_sort_buffer_size = 64M thread_cache_size = 8 query_cache_size = 32M thread_concurrency = 8 datadir = /home/mysql/data wait-timeout = 600 max_connections = 512 max_connect_errors = 10000000 local-infile=0 server-id = 1 log-bin = /home/mysql/log/mysql-bin [mysqldump] quick max_allowed_packet = 16M [mysqld_safe] log-error = /home/mysql/log/mysql_error.log log_slow_queries = /home/mysql/log/slowquery.log long_query_time = 3 [mysql] no-auto-rehash [myisamchk] key_buffer_size = 256M sort_buffer_size = 256M read_buffer = 2M write_buffer = 2M [mysqlhotcopy] interactive-timeout 6.创建目录并修改权限: mkdir -p /home/mysql/log mkdir -p /home/mysql/data chown -R mysql:mysql /home/mysql/date chown -R mysql:mysql /home/mysql/log chown -R mysql:mysql /usr/local/mysql 7.生成新的mysql授权表: /usr/local/mysql/scripts/mysql_install_db --defaults-file=/etc/my.cnf --basedir=/usr/local/mysql --datadir=/home/mysql/data --user=mysql 8.添加mysqld系统服务: cp /usr/src/mysql-5.5.43/support-files/mysql.server /etc/init.d/mysqld chmod +x /etc/init.d/mysqld chkconfig --add mysqld chkconfig --level 2345 mysqld on chkconfig --list | grep mysqld 9.添加加载mysql库文件的路径: cat>/etc/ld.so.conf.d/mysql-x86_64.conf<<EOF /usr/local/mysql/lib /usr/lib64/mysql EOF cp /etc/ld.so.conf.d/mysql-x86_64.conf ldconfig 10.链接mysql可执行文件: ln -s /usr/local/mysql/lib/mysql /usr/lib64/mysql ln -s /usr/local/mysql/include/mysql /usr/include/mysql ln -s /usr/local/mysql/bin/mysql /usr/bin/mysql ln -s /usr/local/mysql/bin/mysqldump /usr/bin/mysqldump ln -s /usr/local/mysql/bin/myisamchk /usr/bin/myisamchk ln -s /usr/local/mysql/bin/mysqld_safe /usr/bin/mysqld_safe ln -s /usr/local/mysql/bin/mysqladmin /usr/bin/mysqladmin 11.启动mysql服务: service mysqld start ps -aux | grep mysqld netstat -anptu | grep :3306 12.登录并修改mysql的root密码: mysql -uroot -p (第一次登录root密码为空) use mysql; update user set password=PASSWORD('root') where user='root'; delete from user where not (user='root'); delete from user where user='root' and password=''; delete from user where Host='localhost.localdomain'; delete from user where Host='::1'; grant all privileges on *.* to root@"%" identified by "root"; update mysql.user set Grant_priv='Y' where Host='%'; flush privileges; 13.刷新MySQL连接主机数量: mysqladmin -uroot -p flush-hosts #输入mysql的root帐号新密码 14.防火墙开启3306端口: iptables -A INPUT -p tcp --dport 3306 -j ACCEPT (责任编辑:IT) |