Maison >base de données >tutoriel mysql >centos664位版本lamp配置第一步:安装配置mysql5.6.x
先安装: yum -y install wget gcc-c ncurses ncurses-devel cmake make perl bison openssl openssl-devel gcc* libevent libevent-devel libxml2 libxml2-devel libmcrypt libmcrypt-devel curl-devel libpng-devel libtool-ltdl-devellibjpeg* libpng* fr
先安装:
yum -y install wget gcc-c++ ncurses ncurses-devel cmake make perl bison openssl openssl-devel gcc* libevent libevent-devel libxml2 libxml2-devel libmcrypt libmcrypt-devel curl-devel libpng-devel libtool-ltdl-devel libjpeg* libpng*
freetype* zlib zlib-devel openldap openldap-devel libxslt-devel* bzip2-devel
1.建立数据库文件目录 如:mkdir /mysqldata
2.下载mysql-5.6.15.tar.gz,并解压
3.运行
cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_DATADIR=/mysqldata \
-DSYSCONFDIR=/etc \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_MEMORY_STORAGE_ENGINE=1 \
-DWITH_READLINE=1 \
-DMYSQL_UNIX_ADDR=/var/lib/mysql/mysql.sock \
-DMYSQL_TCP_PORT=3306 \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DEXTRA_CHARSETS=all \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci
注意datadir和DMYSQL_UNIX_ADDR要分别对应my.cnf里面的datadir和socket
4.make && make install
5. cat /etc/passwd 查看用户列表
cat /etc/group 查看用户组列表
如果没有就创建用户组和用户名:
groupadd mysqluser
add -g mysql mysql
创建相关目录:
mkdir /mysqldata/
mkdir /mysqldata/logs
chown -R mysql:mysql /mysqldata
chown -R mysql:mysql /mysqldata/logs
修改安装目录权限:chown -R mysql:mysql /usr/local/mysql
进入安装目录
cd /usr/local/mysql
删除/etc/my.cnf
vim /usr/local/mysql/my.cnf
[mysqld]
datadir = /mysqldata
socket = /var/lib/mysql/mysql.sock
pid-file = /mysqldata/logs/mysql.pid
user = mysql
port = 3306
default_storage_engine = InnoDB
# InnoDB
#innodb_buffer_pool_size = 128M
#innodb_log_file_size = 48M
innodb_file_per_table = 1
innodb_flush_method = O_DIRECT
# MyISAM
#key_buffer_size = 48M
# character-set
character-set-server=utf8
collation-server=utf8_general_ci
# name-resolve
skip-host-cache
skip-name-resolve
# LOG
log_error = /mysqldata/logs/mysql-error.log
long_query_time = 1
slow-query-log
slow_query_log_file = /mysqldata/logs/mysql-slow.log
# Others
explicit_defaults_for_timestamp=true
#max_connections = 500
open_files_limit = 65535
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
[client]
socket = /var/lib/mysql/mysql.sock
port = 3306
安装自带数据库:
/usr/local/mysql/scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=/mysqldata --user=mysql
注意目录设置要与上面编译的时候一致
ps:如果此处遇到权限不够的错误,请将mysql_install_db 的权限+x
chmod +x mysql_install_db
6.添加开机启动和设置服务
配置my.cnf,配置好后,需要设置权限
chmod -R 755 my.cnf
chown -R mysql:mysql my.cnf
cp support-files/mysql.server /etc/init.d/mysql
chkconfig mysql on
chmod 755 /etc/init.d/mysql
service mysql start --启动MySQL
7.MySQL启动成功后,root默认没有密码,我们需要设置root密码。
设置之前,我们需要先设置PATH,要不不能直接调用mysql
修改/etc/profile文件,在文件末尾添加
PATH=/usr/local/mysql/bin:$PATH
export PATH
关闭文件,运行下面的命令,让配置立即生效
source /etc/profile
现在,我们可以在终端内直接输入mysql进入,mysql的环境了
执行下面的命令修改root密码
mysql -uroot
mysql> SET PASSWORD = PASSWORD('123456');
mysql>flush privileges;
若要设置root用户可以远程访问,执行
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'172.16.%' IDENTIFIED BY 'password' WITH GRANT OPTION;