背景:
阅读新闻
LAMP编译安装与优化
[日期:2014-01-11] 来源:Linux社区 作者:flfeiyu [字体:]
五、MySQL安装与优化
3、MYSQL5.5X以上版本均采用CMAKE安装方式,需要先安装CMAKE工具
#wget
# tar zxvf cmake-2.8.12.1.tar.gz
# cd cmake-2.8.12.1
# ./configure
# make
# make install
3、解压源码包并进入目录
tar xzvf mysql-5.5.33-linux2.6-x86_64.tar.gz
cd mysql-5.5.33-linux2.6-x86_64
4、确认编译环境是否具备
yum -y install gcc* gcc-c++* autoconf* automake* zlib* libxml* ncurses-devel* libgcrypt* libtool*
5、创建mysql安装目录及数据目录
安装目录mkdir /usr/local/mysql
数据存储mkdir /usr/local/mysql/data
6、创建用户和用户组与赋予数据存放目录权限
groupadd mysql
useradd -g mysql mysql
chown mysql.mysql -R /usr/local/mysql
7、进行编译安装,配置编译参数
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_DATADIR=/usr/local/mysql/data \
-DMYSQL_TCP_PORT=3306 \
-DMYSQL_UNIX_ADDR=/usr/local/mysql/data/mysqld.sock \
-DMYSQL_USER=mysql \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DEXTRA_CHARSETS=all \
-DWITH_READLINE=1 \
-DWITH_EMBEDDED_SERVER=1 \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1
make && make install
8、初始化数据库
/usr/local/mysql/scripts/mysql_install_db \
--defaults-file=/etc/my.cnf \
--basedir=/usr/local/mysql \
--datadir=/usr/local/mysql/data \
--user=mysql
9、复制配置文件到/etc目录下并初始化数据库
cp /data/mysql/support-files/my-medium.cnf /etc/my.cnf
10、配置启动脚本
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
11、赋权并修改MYSQL启动位置
chmod +x /etc/init.d/mysql
cp /usr/local/mysql/bin/mysql /usr/bin/
12、启动数据库并配置数据库密码
service mysql start
/usr/local/mysql/bin/mysqladmin -u root password '123456'
[root@hrd ~]# mysql -u root -p
Enter password:
mysql>
或者修改密码
UPDATE user SET password=PASSWORD("new password") WHERE user='root';
13、授权用户本地与远程访问数据库的权限
grant all privileges on *.* to root@'%' identified by 'hrdtech2013';
flush privileges;
14、my.cnf优化
[client]
#password = your_password
port = 3306
socket = /usr/local/mysql/data/mysqld.sock
default-character-set = utf8
# The MySQL server
[mysqld]
port = 3306
socket = /usr/local/mysql/data/mysqld.sock
character-set-server=utf8
log-error = /usr/local/mysql/data
pid-file = /usr/local/mysql/data/hrd.pid
skip-external-locking
key_buffer_size = 256M
max_allowed_packet = 4M
table_open_cache = 1024
sort_buffer_size = 2M
net_buffer_length = 8K
read_buffer_size = 1M
tmp_table_size = 16M
read_rnd_buffer_size = 8M
myisam_sort_buffer_size = 8M
back_log = 200
skip-name-resolve
max_connections = 1000
wait_timeout = 120
thread_concurrency = 8
long_query_time = 2
slow-query_log
slow-query_log_file = /usr/local/mysql/data/slow.log
lower_case_table_names = 1
15、mysql字符集优化
SHOW VARIABLES LIKE 'CHARACTER%'; 查看字符环境
Linux系统文件同步rsync+ssh+inotify+unison实现
相关资讯 lamp
本文评论 查看全部评论 (0)
尊重网上道德,遵守中华人民共和国的各项有关法律法规 承担一切因您的行为而直接或间接导致的民事或刑事法律责任 本站管理人员有权保留或删除其管辖留言中的任意内容 本站有权在网站内转载或引用您的评论 参与本评论即表明您已经阅读并接受上述条款
评论声明
最新资讯