centos mysql 编译安装

centos mysql 编译安装

1.安装

创建MySQL用户

sudo  useradd mysql

下载MySQL的源码包,我们这里使用的时5.5.18

安装依赖

sudo yum -y install cmake gcc-c++ make bison-devel ncurses-devel mysql-devel

防止内置的my.cnf捣乱

sudo mv /etc/my.cnf /etc/my.cnf.bak

解压源码包,

cd /home/xiaohe/tools
tar -zxf mysql-5.5.18.tar.gz
cd mysql-5.5.18
cmake -DCMAKE_INSTALL_PREFIX=/home/xiaohe/mysql -DMYSQL_UNIX_ADDR=/home/xiaohe/mysql/mysql.sock -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_EXTRA_CHARSETS:STRING=utf8,gbk -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DENABLED_LOCAL_INFILE=1 -DMYSQL_DATADIR=/home/xiaohe/mysql/data

make -j2 && make -j2 install

-j2 的2 指的是cpu核心数,有几个核心就是几

手动创建目录

cd /home/xiaohe/mysql && mkdir etc tmp var log

创建配置文件

vim etc/my.cnf
# The following options will be passed to all MySQL clients
[client]
#password   = your_password
port        = 3306
socket      = /home/xiaohe/mysql/mysql.sock

# Here follows entries for some specific programs

# The MySQL server
[mysqld]
!include /etc/mysqld.cnf
port        = 3306
socket      = /home/xiaohe/mysql/mysql.sock
skip-external-locking
log-warnings  = 2
log-error = /home/xiaohe/mysql/log/mysql.err
pid-file  = /home/xiaohe/mysql/var/mysql.pid
basedir = /home/xiaohe/mysql/
datadir = /home/xiaohe/mysql/data/
log-queries-not-using-indexes
long-query-time = 1
#slow-query-log = 1
#slow-query-log-file= /home/xiaohe/mysql/log/slow.log
pid-file  = /home/xiaohe/mysql/var/mysql.pid
tmpdir = /home/xiaohe/mysql/tmp/
slave-load-tmpdir = /home/xiaohe/mysql/tmp/
max_connections = 100
skip-name-resolve
skip-symbolic-links
slave-net-timeout=3
sync_binlog=1
relay_log_recovery=true
key_buffer_size = 16k
sort_buffer_size  = 64K
read_buffer_size  = 256K
read_rnd_buffer_size  = 256K
max_allowed_packet = 1M
table_open_cache = 4
net_buffer_length = 2K

#default_table_type  = INNODB
#transaction_isolation = REPEATABLE-READ

innodb_status_file
innodb_buffer_pool_size = 16M
innodb_additional_mem_pool_size = 2M
innodb_data_home_dir  = /home/xiaohe/mysql/data/
innodb_data_file_path = ibdata1:10M:autoextend
innodb_file_io_threads  = 4
innodb_thread_concurrency = 16
innodb_flush_log_at_trx_commit  = 1
innodb_log_buffer_size  = 8M
innodb_log_group_home_dir = /home/xiaohe/mysql/data/
innodb_log_file_size  = 5M
innodb_log_files_in_group = 2
innodb_max_dirty_pages_pct  = 90
innodb_lock_wait_timeout  = 50

server-id   = 1
log-bin=mysql-bin
binlog_format=mixed
log-slave-updates 
replicate-wild-ignore-table=mysql.%
slave-skip-errors =1062
#read-only
#binlog-ignore-db=mysql
#binlog-do-db=mysql

[mysqldump]
max_allowed_packet  = 16M

[mysql]
no-auto-rehash
max_allowed_packet  = 16M

[myisamchk]
key_buffer_size = 8M
sort_buffer_size = 8M
read_buffer = 2M
write_buffer = 2M

[mysqlhotcopy]
interactive-timeout

初始化数据库

/home/xiaohe/mysql/scripts/mysql_install_db

完成后启动数据库

/home/xiaohe/mysql/bin/mysqld_safe &

检查一下数据库进程,并登陆一下看看,默认没有密码。

修改mysql密码
mysql
mysql> use mysql;
mysql> UPDATE user SET password=password("123456") WHERE user='root';   
mysql> flush privileges;
mysql> exit;
关闭mysql 设置superctl登陆
vim  /home/xiaohe/supervisor/conf/supervisord.conf

[program:mysql-3306]
command= /home/xiaohe/mysql-3306/bin/mysqld --defaults-file=/home/xiaohe/mysql-3306/etc/my.cnf
directory=/home/xiaohe/mysql-3306
user=xiaohe

查看状态

/home/xiaohe/superctl status

加载进去

/home/xiaohe/superctl update
授权
mysql>        grant select,insert,update,delete on *.* to 'root'@'%' identified by '123456' with grant option;   

赋予任何主机访问数据的权限 具体根据实际情况授权,以权限最小化为准

mysql>GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION