博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
CentOS6.7源码安装MySQL5.6
阅读量:5050 次
发布时间:2019-06-12

本文共 5812 字,大约阅读时间需要 19 分钟。

1.源码安装MySQL5.6

# CentOS6操作系统安装完成后,默认会在/etc目录下存在一个my.cnf,# 强制卸载了mysql-libs之后,my.cnf就会消失rpm -qa | grep mysql rpm -e --nodeps mysql-libs-5.1.71-1.el6.x86_64yum -y install make gcc-c++ cmake bison-devel ncurses-develgroupadd mysqluseradd -g mysql mysql -M -s /sbin/nologinmkdir -p /server/toolscd /server/toolswget http://cdn.mysql.com//archives/mysql-5.6/mysql-5.6.21.tar.gztar xf mysql-5.6.21.tar.gzmv /server/tools/mysql-5.6.21 /opt/mysql-5.6.21/ln -s  /opt/mysql-5.6.21/ /application/mysqlcd /application/mysql/cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \-DMYSQL_DATADIR=/data/mysql/data \-DSYSCONFDIR=/usr/local/mysql -DWITH_MYISAM_STORAGE_ENGINE=1 \-DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 \-DWITH_READLINE=1 -DMYSQL_UNIX_ADDR=/usr/local/mysql/var/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_cimake && make installCMake Warning:Manually-specified variables were not used by the project:WITH_READLINEWITH_MEMORY_STORAGE_ENGINECMake Warning手动指定的变量未被项目使用,在这里倒没什么事

目录说明:

a.安装完成后不会生成配置文件,不会给你创建/usr/local/mysql/var/目录,

不会给你创建/data/mysql/data,这些都需要手动创建;

b./opt/mysql-5.6.21/是解压目录;

c.-DCMAKE_INSTALL_PREFIX=/usr/local/mysql/是所有配置文件存放目录;

d.-DMYSQL_DATADIR=/data/mysql/data/是数据及日志存放目录;

e.-DSYSCONFDIR=/usr/local/mysql是my.cnf存放目录;

f.-DMYSQL_UNIX_ADDR是socket存放目录.

2.配置并启动

mkdir -p /data/mysql/datamkdir -p /usr/local/mysql/varchown -R mysql:mysql /usr/local/mysqlchown -R mysql:mysql /data/mysql/datacd /usr/local/mysql# 如果不小心删除了这个数据目录或这个目录下的文件被误操作删除了,可以利用这个命令重新初始化./scripts/mysql_install_db --basedir=/usr/local/mysql \--datadir=/data/mysql/data --user=mysqlcp support-files/mysql.server /etc/init.d/mysqldchkconfig mysqld onecho "export PATH=/usr/local/mysql/bin:$PATH" >> /etc/profilesource /etc/profile

my.cnf

cat > /usr/local/mysql/my.cnf << EOF[client]port = 3306socket = /usr/local/mysql/var/mysql.sock  [mysqld]port = 3306socket = /usr/local/mysql/var/mysql.sock  basedir = /usr/local/mysqldatadir = /data/mysql/datapid-file = /data/mysql/data/mysql.piduser = mysqlbind-address = 0.0.0.0server-id = 1sync_binlog=1log_bin = mysql-bin  skip-name-resolve#skip-networkingback_log = 600  max_connections = 3000max_connect_errors = 3000##open_files_limit = 65535table_open_cache = 512max_allowed_packet = 16Mbinlog_cache_size = 16Mmax_heap_table_size = 16Mtmp_table_size = 256M  read_buffer_size = 1024Mread_rnd_buffer_size = 1024Msort_buffer_size = 1024Mjoin_buffer_size = 1024Mkey_buffer_size = 8192M  thread_cache_size = 8  query_cache_size = 512Mquery_cache_limit = 1024M  ft_min_word_len = 4  binlog_format = mixedexpire_logs_days = 30  log_error = /data/mysql/data/mysql-error.logslow_query_log = 1long_query_time = 1slow_query_log_file = /data/mysql/data/mysql-slow.log  performance_schema = 0explicit_defaults_for_timestamp  ##lower_case_table_names = 1  skip-external-locking  default_storage_engine = InnoDB##default-storage-engine = MyISAMinnodb_file_per_table = 1innodb_open_files = 500innodb_buffer_pool_size = 4096Minnodb_write_io_threads = 1000innodb_read_io_threads = 1000innodb_thread_concurrency = 8innodb_purge_threads = 1innodb_flush_log_at_trx_commit = 2innodb_log_buffer_size = 4Minnodb_log_file_size = 32Minnodb_log_files_in_group = 3innodb_max_dirty_pages_pct = 90innodb_lock_wait_timeout = 120  bulk_insert_buffer_size = 8Mmyisam_sort_buffer_size = 8Mmyisam_max_sort_file_size = 2Gmyisam_repair_threads = 1  interactive_timeout = 28800wait_timeout = 28800  [mysqldump]quickmax_allowed_packet = 16M  [myisamchk]key_buffer_size = 8Msort_buffer_size = 8Mread_buffer = 4Mwrite_buffer = 4M  sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLESport = 3306EOF

3.授权

# 第一次给root设置密码mysqladmin -u root password 'oldboy123'# 给root修改密码mysqladmin -uroot -poldboy123 password'oldboy123456'# 设置root用户可以远程访问GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'Root123!@#' WITH GRANT OPTION;FLUSH PRIVILEGES;

4.注意事项及常见报错

a.在启动MySQL服务时,会按照一定次序搜索my.cnf,先在/etc目录下找,找不到,则会搜索"$basedir/my.cnf",在本例中就是 /usr/local/mysql/my.cnf,这是新版MySQL的配置文件的默认位置;b.在CentOS 6.4版操作系统最小安装完成后,默认会在/etc目录下存在一个my.cnf,需要将此文件更名为其他的名字,如:/etc/my.cnf.bak(上面的强制卸载,已经把这个文件给删了)否则,该文件会干扰源码安装的MySQL的正确配置,造成无法启动;c.在使用"yum update"更新系统后,需要检查下/etc目录下是否会多出一个my.cnf,如果多出,将它重命名成别的.否则,MySQL将使用这个配置文件启动,可能造成无法正常启动等问题.d.用ps -ef查看mysql进程,出现两条斜线是因为配置文件中多加了一个斜线:basedir = /usr/local/mysql//usr/local/mysql//bin/mysqld_safe

e.登陆mysql,若是报错如下:

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
解决办法:

mkdir /var/lib/mysql/

ln -s /usr/local/mysql/var/mysql.sock /var/lib/mysql/mysql.sock

f.如果启动报错:

service mysql start

Starting MySQL.Logging to '/data/mysql/data/mysql-error.log'.

mysqld_safe Directory '/usr/local/mysql/var' for UNIX socket file don't exists.

ERROR! The server quit without updating PID file (/data/mysql/data/mysql.pid).

解决办法:

mkdir /usr/local/mysql/varchown -R mysql:mysql /usr/local/mysqlservice mysql start出这个错的原因应该是:在cmake的时候这一句---DMYSQL_UNIX_ADDR=/var/lib/mysql/mysql.sock导致的,改成指向配置文件中的就应该不会再报错了.

5.centos7下启动mysql时的一个报错

service mysql start

mysqld_safe error: log-error set to '/var/log/mariadb/mariadb.log',

mysqld_safe error: log-error set to '/var/log/mariadb/mariadb.log',however file don't exists.

Create writable for user 'mysql'.The server quit without updating PID file (/data/mysql/data[FAILED]id).

该问题为mysql的一个小bug,临时处理办法为:直接创建一个 log-error 指定的空文件,

并给适当的属主、属组权限即可.该问题已经在版本 5.5.55, 5.6.36, 5.7.18, 8.0.1中修复.

mkdir -p /var/log/mariadbtouch /var/log/mariadb/mariadb.logchown -R mysql.mysql /var/log/mariadbservice mysql startln -s /var/log/mariadb/mariadb.log /data/mysql/data/mysql-error.log/etc/init.d/mysql restart

 

参考博客:http://www.cnblogs.com/kevingrace/p/6109679.html

转载于:https://www.cnblogs.com/fawaikuangtu123/p/10169828.html

你可能感兴趣的文章
BZOJ 2338 HNOI2011 数矩形 计算几何
查看>>
关于页面<!DOCTYPE>声明
查看>>
【AS3代码】播放FLV视频流的三步骤!
查看>>
C++标准库vector使用(更新中...)
查看>>
cocos2d-x 2.2.6 之 .xml文件数据读取
查看>>
枚举的使用
查看>>
BZOJ 1531 二进制优化多重背包
查看>>
BZOJ 2324 (有上下界的)费用流
查看>>
python3基础06(随机数的使用)
查看>>
Zookeeper系列(二)特征及应用场景
查看>>
【HTTP】Fiddler(三)- Fiddler命令行和HTTP断点调试
查看>>
Spring Boot使用Druid和监控配置
查看>>
poi 处理空单元格
查看>>
Android 内存泄漏优化总结
查看>>
luogu4849 寻找宝藏 (cdq分治+dp)
查看>>
Spring Cloud微服务笔记(五)Feign
查看>>
C语言键盘按键列表
查看>>
Codeforces Round #374 (Div. 2)
查看>>
oracle数据类型
查看>>
socket
查看>>