# useradd -r -s /sbin/nologin -M mysql
# mkdir -p /opt/mysql/data/
# yum -y install make gcc-c++ cmake bison-devel ncurses-devel
# /etc/init.d/iptables stop
# chkconfig iptables off
# sed -i 's#SELINUX=enforcing#SELINUX=disabled#g' /etc/selinux/config
# yum -y install make gcc-c++ cmake bison-devel ncurses-devel
cmake \
-DCMAKE_INSTALL_PREFIX=/opt/mysql \
-DMYSQL_DATADIR=/opt/mysql/data/ \
-DSYSCONFDIR=/etc \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_MEMORY_STORAGE_ENGINE=1 \
-DWITH_READLINE=1 \
-DMYSQL_UNIX_ADDR=/tmp/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
# make && make install
# chown root.mysql mysql -R
# chown mysql.mysql mysql/data/ -R
#初始化
# cd mysql
# ./scripts/mysql_install_db --basedir=/opt/mysql/ --datadir=/opt/mysql/data/ --user=mysql
# mv /etc/my.cnf /etc/my.cnf.bak
# cd /opt/mysql-5.5.40/support-files
# egrep -v "^#|^$" my-innodb-heavy-4G.cnf > /etc/my.cnf
# cat /etc/my.cnf
[client]
port = 3306
socket = /tmp/mysql.sock
[mysqld]
port = 3307
socket = /tmp/mysql.sock
basedir = /opt/mysql/
datadir = /opt/mysql/data
back_log = 50
max_connections = 250
max_connect_errors = 10000
table_open_cache = 2048
max_allowed_packet = 16M
binlog_cache_size = 1M
max_heap_table_size = 64M
read_buffer_size = 2M
read_rnd_buffer_size = 16M
sort_buffer_size = 8M
join_buffer_size = 8M
thread_cache_size = 8
thread_concurrency = 8
query_cache_size = 64M
query_cache_limit = 2M
ft_min_word_len = 4
default-storage-engine = innodb
character_set_server = utf8
skip-name-resolve
thread_stack = 192K
transaction_isolation = REPEATABLE-READ
tmp_table_size = 64M
log-bin=mysql-bin
binlog_format=mixed
slow_query_log
long_query_time = 2
server-id = 1
key_buffer_size = 32M
bulk_insert_buffer_size = 64M
myisam_sort_buffer_size = 128M
myisam_max_sort_file_size = 10G
myisam_repair_threads = 1
myisam_recover
innodb_additional_mem_pool_size = 16M
innodb_buffer_pool_size = 2G
innodb_data_file_path = ibdata1:10M:autoextend
innodb_write_io_threads = 8
innodb_read_io_threads = 8
innodb_thread_concurrency = 16
innodb_flush_log_at_trx_commit = 1
innodb_log_buffer_size = 8M
innodb_log_file_size = 256M
innodb_log_files_in_group = 3
innodb_max_dirty_pages_pct = 90
innodb_lock_wait_timeout = 120
[mysqldump]
quick
max_allowed_packet = 16M
[mysql]
no-auto-rehash
[myisamchk]
key_buffer_size = 512M
sort_buffer_size = 512M
read_buffer = 8M
write_buffer = 8M
[mysqlhotcopy]
interactive-timeout
[mysqld_safe]
open-files-limit = 8192
#启动
bin/mysqld_safe --user=mysql &
cp support-files/mysql.server /etc/init.d/
# chmod +x /etc/init.d/mysql.server
chkconfig mysql.server on
service mysql.server start --启动MySQL
echo 'PATH=/opt/mysql/bin:$PATH' >> /etc/profile
echo 'export PATH' >> /etc/profile
source /etc/profile
给root用户添加密码
# mysqladmin -u root password "password"
# ./mysql/bin/mysqladmin -uroot -h 127.0.0.1 password "xxx"
# ./mysql/bin/mysql
mysql> drop database test;
mysql> drop user root@"::1";
Query OK, 0 rows affected (0.00 sec)
mysql> drop user ''@"localhost";
Query OK, 0 rows affected (0.00 sec)
mysql> drop user ''@"xxx";
Query OK, 0 rows affected (0.00 sec)
mysql> drop user 'root'@"xxx";
Query OK, 0 rows affected (0.00 sec)
mysql> select user,host,password from mysql.user;
+------+-----------+-------------------------------------------+
| user | host | password |
+------+-----------+-------------------------------------------+
| root | localhost | *45B4FBDCF0E43CE915C9A18E1EF11F78FE76AB17 |
| root | 127.0.0.1 | *45B4FBDCF0E43CE915C9A18E1EF11F78FE76AB17 |
+------+-----------+-------------------------------------------+
注:在启动MySQL服务时,会按照一定次序搜索my.cnf,先在/etc目录下找,找不到则会搜索"$basedir/my.cnf",在本例中就是 /usr/local/mysql/my.cnf,这是新版MySQL的配置文件的默认位置!
注意:在CentOS 6.4版操作系统的最小安装完成后,在/etc目录下会存在一个my.cnf,需要将此文件更名为其他的名字,如:/etc/my.cnf.bak,否则,该文件会干扰源码安装的MySQL的正确配置,造成无法启动。
在使用"yum update"更新系统后,需要检查下/etc目录下是否会多出一个my.cnf,如果多出,将它重命名成别的。否则,MySQL将使用这个配置文件启动,可能造成无法正常启动等问题。
server_id = 223
log-bin=mysql-bin
grant replication slave on *.* to 'backup'@'192.168.1.224' identified by 'medlinker';
show master status;
change master to master_host='192.168.1.223',master_user='backup',master_password='medlinker',master_log_file='mysql-bin.000002',master_log_pos=120;
start slave;
show slave status\G
授权开发使用:
grant all on *.* to 'root'@'%' identified by 'medlinker';
二进制安装mysql 5.6
tar xf mysql-5.6.29-linux-glibc2.5-x86_64.tar.gz
ln -sv mysql-5.6.29-linux-glibc2.5-x86_64 mysql
useradd -r -s /sbin/nologin -M mysql
chown mysql.mysql mysql-5.6.29-linux-glibc2.5-x86_64 -R
cd scripts/
./mysql_install_db --basedir=/opt/mysql --datadir=/opt/mysql/data/ --user=mysql
./bin/mysqld_safe --defaults-file=my.cnf &
netstat -tnulp
二进制安装mysql 5.7
shell> groupadd mysql
shell> useradd -r -g mysql -s /bin/false mysql
shell> cd /usr/local
shell> tar zxvf /path/to/mysql-VERSION-OS.tar.gz
shell> ln -s full-path-to-mysql-VERSION-OS mysql
shell> cd mysql
shell> mkdir mysql-files
shell> chmod 770 mysql-files
shell> chown -R mysql .
shell> chgrp -R mysql .
shell> bin/mysql_install_db --user=mysql # Before MySQL 5.7.6
shell> bin/mysqld --initialize --user=mysql # MySQL 5.7.6 and up
shell> bin/mysql_ssl_rsa_setup # MySQL 5.7.6 and up
shell> chown -R root .
shell> chown -R mysql data mysql-files
shell> bin/mysqld_safe --user=mysql &
初始化数据库,注意密码
./bin/mysqld --initialize --basedir=/opt/mysql7/ --datadir=/opt/mysql7/data/ --user=mysql
./bin/mysqld_safe --user=mysql &
# ./bin/mysqladmin -u root -p password "wqh"
mysql> alter user 'root'@'localhost' identified by 'mysql';
mysql> flush privileges;