MYSQL 源码安装:
修改参数文件:
vi /etc/security/limits.conf
mysql soft nproc 2047
mysql hard nproc 16384
mysql soft nofile 1024
mysql hard nofile 65536
下载5.6.37源码
解压后用cmake安装:
cmake . -DCMAKE_INSTALL_PREEIX=/usr/local/mysql \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DENABLED_LOCAL_INFILE=ON \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWICH_FEDERATED_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITHOUT_EXAMPLE_STORAGE_ENGINE=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DWITH_PREFSCHEMA_STORAGE_ENGINE=1 \
-DCOMPILATION_COMMENT='JSS for mysqltest' \
-DWITH_READLINE=ON \
-DSYSCONFDIR=/data/mysqldata/3306 \
-DMYSQL_UNIX_ADDR=/data/mysqldata/3306/mysql.sock
编译称重后安装
make && make install
chown -R mysql:mysql /usr/local/mysql
export LANG=zh_CN.CB18030
export PATH=/usr/local/mysql/bin:$PATH
cd /data/
mkdir -p /data/mysqldata/{3306/{data,tmp,binlog},backup,scripts}
chown -R mysql:mysql mysqldata
su - mysql
cd /usr/local/mysql
编辑参数文件
/data/mysqldata/3306/my.cnf
[client]
port = 3306
socket = /data/mysqldata/3306/mysql.sock
#The MySQL server
[mysqld]
port =3306
user =mysql
socket =/data/mysqldata/3306/mysql.sock
pid-file=/data/mysqldata/3306/mysql.pid
basedir =/usr/local/mysql
datadir =/data/mysqldata/3306/data
tmpdir =/data/mysqldata/3306/tmp
open_files_limit =10240
explicit_defaults_for_timestamp
sql_mode =NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
#Buffer
max_allowed_packet =256m
max_heap_table_size =256m
net_buffer_length =8k
sort_buffer_size =2m
join_buffer_size =4m
read_buffer_size =2m
read_rnd_buffer_size =16m
#Log
log-bin =/data/mysqldata/3306/binlog/mysql-bin
binlog_cache_size =32m
max_binlog_cache_size =512m
max_binlog_size =512m
binlog_format =mixed
log_output =FILE
log-error =../mysql-error.log
slow_query_log =1
slow_query_log_file =../slow_query.log
general_log =0
general_log_file =../general_query.log
expire-logs-days =14
#InnoDB
innodb_data_file_path =ibdata1:2048m:autoextend
innodb_log_file_size =256m
innodb_log_files_in_group =3
innodb_buffer_pool_size =1024m
[mysql]
no-auto-rehash
prompt =(\u@\h) [\d]>\_
default-character-set=gbk
初始化db
/usr/local/mysql/scripts/mysql_install_db --datadir=/data/mysqldata/3306/data --basedir=/usr/local/mysql
此处因为参数文件手敲,出现了错误,需要重新初始化,步骤为:
1 删除/usr/local/mysql/my.cnf
2 删除/data/mysqldata/3306下除了my.cnf外的所有文件,并重新创建此目录下的binlog,data,tmp目录
3 重新运行初始化脚本
启动mysql
mysqld_safe --defaults-file=/data/mysqldata/3306/my.cnf &
netstat -lnt|grep 3306
ps -ef|grep bin/mysql|grep -v grep
设置管理员用户与密码:
mysql
select user,host from mysql.user ;
delete from mysql.user where (user,host) not in (select 'root','localhost');
update mysql.user set user='system',password=password('xxxxxxxxx');
truncate table mysql.db;
flush privileges;
这样就安全了。
以上是mysql使用源码安装和配置root用户的全过程