安装mysql
yum install cmake -y 否则装mysql时候报错:-bash: cmake: command not found
groupadd mysql
useradd -r -g mysql mysql
tar zxvf cmake-3.0.0.tar.gz
cd cmake-3.0.0
./bootstrap
gmake & gmake install
报错:make clean 再次 gmake & make install
gmake[2]: *** [bin/cmake] Error 1
gmake[1]: *** [Source/CMakeFiles/cmake.dir/all] Error 2)
tar zxvf mysql-5.6.19.tar.gz
cd mysql-5.6.19
cmake . \
-DCMAKE_INSTALL_PREFIX=/home/mysql \
-DMYSQL_DATADIR=/home/mysql/data \
-DMYSQL_UNIX_ADDR=/home/mysql/mysqld.sock \
-DDEFAULT_CHARSET=utf8 \
-DEXTRA_CHARSETS=all \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_SPHINX_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_MEMORY_STORAGE_ENGINE=1 \
-DWITH_READLINE=1 \
-DENABLED_LOCAL_INFILE=1 \
-DMYSQL_USER=mysql
make
make install
//报错:
-- Could NOT find Curses (missing: CURSES_LIBRARY CURSES_INCLUDE_PATH)
CMake Error at cmake/readline.cmake:85 (MESSAGE):
Curses library not found. Please install appropriate package,
remove CMakeCache.txt and rerun cmake.On Debian/Ubuntu, package name is libncurses5-dev, on Redhat and derivates it is ncurses-devel.
Call Stack (most recent call first):
cmake/readline.cmake:128 (FIND_CURSES)
cmake/readline.cmake:202 (MYSQL_USE_BUNDLED_EDITLINE)
CMakeLists.txt:417 (MYSQL_CHECK_EDITLINE)
-- Configuring incomplete, errors occurred!
See also "/root/src/mysql-5.6.19/CMakeFiles/CMakeOutput.log".
See also "/root/src/mysql-5.6.19/CMakeFiles/CMakeError.log"
----------------解决方法---------
rm -rf CMakeCache.txt
yum install ncurses-devel -y
cd /root/src/cmake-3.0.0
find ./ -name CMakeCache.txt
会显示如下内容:
会显示如下内容:
./Tests/CMakeFiles/CheckFortran/CMakeCache.txt
./Tests/ComplexOneConfig/Cache/CMakeCache.txt
./Tests/RunCMake/CommandLine/cache-bad-generator/CMakeCache.txt
./Tests/RunCMake/CommandLine/cache-no-generator/CMakeCache.txt
./Tests/Complex/Cache/CMakeCache.txt
删除下列内容:
rm -rf CMakeCache.txt
rm -rf /root/src/cmake-3.0.0/Tests/CMakeFiles/CheckFortran/CMakeCache.txt
rm -rf /root/src/cmake-3.0.0/Tests/ComplexOneConfig/Cache/CMakeCache.txt
rm -rf /root/src/cmake-3.0.0/Tests/RunCMake/CommandLine/cache-bad-generator/CMakeCache.txt
rm -rf /root/src/cmake-3.0.0/Tests/RunCMake/CommandLine/cache-no-generator/CMakeCache.txt
rm -rf /root/src/cmake-3.0.0/Tests/Complex/Cache/CMakeCache.txt
重新编译
cmake . \
-DCMAKE_INSTALL_PREFIX=/home/mysql \
-DMYSQL_DATADIR=/home/mysql/data \
-DMYSQL_UNIX_ADDR=/home/mysql/mysqld.sock \
-DDEFAULT_CHARSET=utf8 \
-DEXTRA_CHARSETS=all \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_SPHINX_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_MEMORY_STORAGE_ENGINE=1 \
-DWITH_READLINE=1 \
-DENABLED_LOCAL_INFILE=1 \
-DMYSQL_USER=mysql
mv /etc/my.cnf /etc/my.cnf.bak
#cp support-files/my-default.cnf /etc/my.cnf
#mkdir -p /home/mysql/data
mkdir -p /home/mysql/log
参考my.cnf配置文件配置
vi /etc/my.cnf
[mysqld]
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
port = 3306
#socket = /tmp/mysql.sock
socket =/home/mysql/mysqld.sock
key_buffer_size = 512M
sort_buffer_size = 8M
read_buffer_size = 4M
myisam_sort_buffer_size = 64M
thread_cache_size = 200
back_log = 300
thread_concurrency = 64
datadir = /home/mysql/data
long_query_time = 1
slow_query_log = ON
slow_query_log_file='/home/mysql/log/slowsql.log'
log-error= /home/mysql/log/mysql-error.log
pid-file= /home/mysql/log/mysql.pid
tmpdir=/home/mysql/log
event_scheduler=ON
wait_timeout = 180
max_connections = 8000
max_connect_errors = 10000000
query_cache_size=536870912
join_buffer_size=4194304
read_rnd_buffer_size=2097152
table_open_cache=1024
query_cache_limit=536870912
default_storage_engine = innodb
innodb_buffer_pool_size=30G
innodb_additional_mem_pool_size = 32M
innodb_flush_log_at_trx_commit = 1
innodb_max_dirty_pages_pct=90
bulk_insert_buffer_size=512M
expire_logs_days=7
innodb_use_sys_malloc = 1
explicit_defaults_for_timestamp=true
log-bin=mysql-bin
#binlog_format=ROW
binlog_format=MIXED
server-id = 1
sync_binlog = 1
#如果innodb_flush_log_at_trx_commit设置为0,log buffer将每秒一次地写入log file中,并且log file的flush(刷到磁盘)操作同时进行.该模式下,在事务提交的时候,不会主动触发写入磁盘的操作。
#如果innodb_flush_log_at_trx_commit设置为1,每次事务提交时MySQL都会把log buffer的数据写入log file,并且flush(刷到磁盘)中去
#如果innodb_flush_log_at_trx_commit设置为2,每次事务提交时MySQL都会把log buffer的数据写入log file.但是flush(刷到磁盘)操作并不会同时进行。该模式下,MySQL会每秒执行一次 flush(刷到磁盘)操作
lower_case_table_names=1
log_bin_trust_function_creators=1
innodb_flush_logs_at_trx_commit = 1
#skip_slave_start
#read_only
skip-name-resolve #参数的目的是不再进行反解析(ip不反解成域名),这样可以加快数据库的反应时间
[mysqldump]
quick
max_allowed_packet = 16M
[mysql]
no-auto-rehash
[myisamchk]
key_buffer_size = 256M
sort_buffer_size = 256M
read_buffer = 2M
write_buffer = 2M
[mysqlhotcopy]
interactive_timeout=30
复制启动脚本:
cd /home/mysql
cp ./support-files/mysql.server /etc/init.d/mysqld
vi /etc/init.d/mysqld
修改:
basedir=
datadir=
为
basedir=/home/mysql
basedir=/home/mysql
datadir=/home/mysql/data
chmod 755 /etc/init.d/mysqld
chkconfig --add mysqld
chkconfig --level 345 mysqld on
chkconfig --list mysqld
初始化数据库:
之前:vim /etc/hosts 加上 127.0.0.1 hostsname
cd /home/mysql
chown -R mysql:mysql /home/mysql
cd /home/mysql/mysql-5.6.19
make
make install
chown -R mysql:mysql /home/mysql
./scripts/mysql_install_db --user=mysql --base=/home/mysql/ --datadir=/home/mysql/data/ --explicit_defaults_for_timestamp
提示 Installing MySQL system tables...OK
(如果报错,请试试添加如下环境变量试试,如不报错,接下来才去配置环境变量)
sql加入到环境变量
vi /etc/profile
#mysql
export PATH=$PATH:$HOME/bin:/home/mysql/bin:/home/mysql/lib
source /etc/profile
/etc/init.d/mysqld restart
添加权限
mysql -uroot -p
=========================================
(
默认空密码回车
报错
[mysql@jsjxapp ~]$ mysql -uroot -p
Enter password:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/home/mysql/mysqld.sock' (2)
看一下/etc/my.cnf
我是留下 socket = /home/mysql/mysqld.sock
发现只有/tmp/mysqld.sock 而/home/mysql下面没做有,找不到mysql.sock,英明的我果断做了个软连接
ln -s /tmp/mysqld.sock /home/mysql/mysqld.sock
再次
mysql -uroot -p 空密码回车,解决问题
)
==========================================
use mysql;
delete from user where not (user='root') ;
delete from user where user='root' and password='';
grant all on *.* to root@'localhost' identified by 'rootdb!xxx' with grant option ;
grant all on *.* to jsjx@'%' identified by 'jsjxdb';
grant all on *.* to select_v@'%' identified by 'mysql_select';
select host,user,password from mysql.user;
flush privileges;
动主库生效,并赋予从库权限帐号,允许用户在主库上读取日志
GRANT REPLICATION SLAVE ON *.* TO 'slave'@'%' IDENTIFIED BY 'slave.123#!';
flush privileges;
select host,user,password from mysql.user;
主:
flush tables with read lock;
show master status;
unlock tables;
从:
stop slave;
change master to master_host='192.168.2.100',master_user='slave',master_password='slave.123#!',master_port=3306,master_log_file='mysql-bin.000007',master_log_pos=4;
start slave;
show slave status\G;
如果Slave_IO_Running、Slave_SQL_Running状态为Yes则表明设置成功。
从库的my.cnf添加
server-id = 2
#replicate-ignore-db=mysql,information_schema,test
#log-slave-updates
replicate-wild-ignore-table=mysql.%
replicate-wild-ignore-table=test.%
replicate-wild-ignore-table=information_schema.%
replicate-wild-ignore-table=performance_schema.%
运维QQ交流群:171586999