CentOS 6.5安装MySQL(LAMP)
时间:2016-04-02 03:30 来源:linux.it.net.cn 作者:IT
1.清除系统中mysql痕迹:
yum remove mysql
rm -rvf /etc/my.cnf
2.创建mysql用户和用户组:
groupadd mysql
useradd -s /sbin/nologin -M -g mysql mysql
3.解压:
tar zxvf mysql-5.5.14.tar.gz -C /usr/src/
4.配置:
cd /usr/src/mysql-5.5.14/
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
5.编译:
make
6.安装:
make install
7.编辑my.cnf配置文件:
cp /usr/src/mysql-5.5.14/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
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 = 10
max_connections = 512
max_connect_errors = 10000000
local-infile=0
server-id = 1
[mysqldump]
quick
max_allowed_packet = 16M
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
[mysql]
no-auto-rehash
[myisamchk]
key_buffer_size = 256M
sort_buffer_size = 256M
read_buffer = 2M
write_buffer = 2M
[mysqlhotcopy]
interactive-timeout
8.修改目录权限、生成新的mysql授权表:
mkdir -p /home/mysql/data
chown -R mysql:mysql /home/mysql/data
chown -R mysql:mysql /usr/local/mysql
/usr/local/mysql/scripts/mysql_install_db --defaults-file=/etc/my.cnf --basedir=/usr/local/mysql --datadir=/home/mysql/data --user=mysql
9.添加mysqld系统服务:
cp /usr/src/mysql-5.5.14/support-files/mysql.server /etc/init.d/mysqld
chmod a+x /etc/init.d/mysqld
chkconfig --add mysqld
chkconfig --level 2345 mysqld on
chkconfig --list | grep mysqld
10.添加加载mysql库文件的路径:
vim /etc/ld.so.conf.d/mysql-x86_64.conf
/usr/local/mysql/lib
/usr/lib64/mysql
cp /etc/ld.so.conf.d/mysql-x86_64.conf /etc/ld.so.conf.d/mysql.conf
ldconfig
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
(空密码能成功登录,mysql成功安装完成)
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;
(责任编辑:IT)
1.清除系统中mysql痕迹: yum remove mysql rm -rvf /etc/my.cnf 2.创建mysql用户和用户组: groupadd mysql useradd -s /sbin/nologin -M -g mysql mysql 3.解压: tar zxvf mysql-5.5.14.tar.gz -C /usr/src/ 4.配置: cd /usr/src/mysql-5.5.14/ 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 5.编译: make 6.安装: make install 7.编辑my.cnf配置文件: cp /usr/src/mysql-5.5.14/support-files/my-medium.cnf /etc/my.cnf vim /etc/my.cnf [client] port socket [mysqld] port socket 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 = 10 max_connections = 512 max_connect_errors = 10000000 local-infile=0 server-id = 1 [mysqldump] quick max_allowed_packet = 16M [mysqld_safe] log-error=/var/log/mysqld.log pid-file=/var/run/mysqld/mysqld.pid [mysql] no-auto-rehash [myisamchk] key_buffer_size = 256M sort_buffer_size = 256M read_buffer = 2M write_buffer = 2M [mysqlhotcopy] interactive-timeout 8.修改目录权限、生成新的mysql授权表: mkdir -p /home/mysql/data chown -R mysql:mysql /home/mysql/data chown -R mysql:mysql /usr/local/mysql /usr/local/mysql/scripts/mysql_install_db --defaults-file=/etc/my.cnf --basedir=/usr/local/mysql --datadir=/home/mysql/data --user=mysql 9.添加mysqld系统服务: cp /usr/src/mysql-5.5.14/support-files/mysql.server /etc/init.d/mysqld chmod a+x /etc/init.d/mysqld chkconfig --add mysqld chkconfig --level 2345 mysqld on chkconfig --list | grep mysqld 10.添加加载mysql库文件的路径: vim /etc/ld.so.conf.d/mysql-x86_64.conf /usr/local/mysql/lib /usr/lib64/mysql cp /etc/ld.so.conf.d/mysql-x86_64.conf ldconfig 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 (空密码能成功登录,mysql成功安装完成) 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; (责任编辑:IT) |