Linux centos lamp--mysql编译安装

在CentOS7上可以直接使用yum安装LAMP(Linux+Apache[httpd]+Mysql+PHP),比手动编译安装LAMP要简单的多,但在实际的生产环境中都会手动编译LAMP,使用手动编译LAMP有以下几个优点

方便扩展模块,如添加PHP的扩展模块、http扩展模块等,可根据实际需求进行配置;
可以自由的选择安装较适合的版本,系统自带的httpd、mysql或者PHP的版本可能较低不能满足某些应用需求;
可以以fpm的方式运行PHP,一般系统自带的PHP都是以httpd模块的形式运行的,若需要让PHP已fpm的方式运行,必须手动编译安装httpd和PHP;

1、 配置yum本地源
vim /etc/profile
再最后添加下面一行
export PATH=/usr/local/mysql/bin:$PATH

执行source /etc/profile
更新环境变量

mount /dev/sr0 /media

vim /etc/yum.repos.d/CentOS-Media.repo
[c7-media]
name=CentOS-$releasever - Media
baseurl=file:///media/
#baseurl=ftp://192.168.1.21/media/
#baseurl=http://192.168.1.21/media/
gpgcheck=0
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

禁用网络源
mv CentOS-Base.repo CentOS-Base.repo.bak
启用网络源
mv CentOS-Base.repo.bak CentOS-Base.repo

2、 Centos下用cmake编译安装MySQL 5.7 mariadb
安装依赖包
yum -y install openssl-devel gcc gcc-c++ ncurses ncurses-devel cmake lrzsz
下载相应源码包
cd /usr/local/
wget http://downloads.sourceforge.net/project/boost/boost/1.59.0/boost_1_59_0.tar.gz
wget http://www.mysql.com/Downloads/MySQL-5.7/mysql-5.7.28.tar.gz
添加mysql用户
useradd -M -s /sbin/nologin mysql
预编译
tar xzf boost_1_59_0.tar.gz
tar xzf mysql-5.7.28.tar.gz
mkdir -p /data/mysql
chown -R mysql.mysql /data/mysql
mv boost_1_59_0 /usr/local/boost
cd mysql-5.7.28
#从MySQL 5.7.5开始Boost库是必需的

配置
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/data/mysql -DWITH_BOOST=/usr/local/boost -DSYSCONFDIR=/etc -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DWITH_FEDERATED_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_MYISAM_STORAGE_ENGINE=1 -DENABLED_LOCAL_INFILE=1 -DENABLE_DTRACE=0 -DDEFAULT_CHARSET=utf8mb4 -DDEFAULT_COLLATION=utf8mb4_general_ci -DWITH_EMBEDDED_SERVER=1
编译安装
make #编译很消耗系统资源,小内存可能编译通不过
make install
编译出错,删除下面文件,重新编译安装。
#rm -f CMakeCache.txt
#make && make install

3、服务配置
启动脚本,设置开机自启动
/bin/cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
chmod +x /etc/init.d/mysqld
开机启动
chkconfig --add mysqld
chkconfig mysqld on/off
systemctl enable mysqld.service
disable

修改配置文件
/etc/my.cnf,仅供参考
mv /etc/my.cnf /etc/my.cnf.bak

vim /etc/my.cnf
[client]
port = 3306
socket = /tmp/mysql.sock
default-character-set = utf8mb4
[mysqld]
port = 3306
socket = /tmp/mysql.sock
basedir = /usr/local/mysql
datadir = /data/mysql
pid-file = /data/mysql/mysql.pid
user = mysql
bind-address = 0.0.0.0
server-id = 1
init-connect = ‘SET NAMES utf8mb4’
character-set-server = utf8mb4
#skip-name-resolve
#skip-networking
back_log = 300
max_connections = 1000
max_connect_errors = 6000
open_files_limit = 65535
table_open_cache = 128
max_allowed_packet = 4M
binlog_cache_size = 1M
max_heap_table_size = 8M
tmp_table_size = 16M
read_buffer_size = 2M
read_rnd_buffer_size = 8M
sort_buffer_size = 8M
join_buffer_size = 8M
key_buffer_size = 4M
thread_cache_size = 8
query_cache_type = 1
query_cache_size = 8M
query_cache_limit = 2M
ft_min_word_len = 4
log_bin = mysql-bin
binlog_format = mixed
expire_logs_days = 30
log_error = /data/mysql/mysql-error.log
slow_query_log = 1
long_query_time = 1
slow_query_log_file = /data/mysql/mysql-slow.log
performance_schema = 0
explicit_defaults_for_timestamp
#lower_case_table_names = 1
skip-external-locking
default_storage_engine = InnoDB
#default-storage-engine = MyISAM
innodb_file_per_table = 1
innodb_open_files = 500
innodb_buffer_pool_size = 64M
innodb_write_io_threads = 4
innodb_read_io_threads = 4
innodb_thread_concurrency = 0
innodb_purge_threads = 1
innodb_flush_log_at_trx_commit = 2
innodb_log_buffer_size = 2M
innodb_log_file_size = 32M
innodb_log_files_in_group = 3
innodb_max_dirty_pages_pct = 90
innodb_lock_wait_timeout = 120
bulk_insert_buffer_size = 8M
myisam_sort_buffer_size = 8M
myisam_max_sort_file_size = 10G
myisam_repair_threads = 1
interactive_timeout = 28800
wait_timeout = 28800

初始化数据库
注:
之前版本mysql_install_db是在mysql_basedir/script下,5.7放在了mysql_install_db/bin目录下,且已被废弃
“–initialize"会生成一个随机密码(~/.mysql_secret),而”–initialize-insecure"不会生成密码
–datadir目标目录下不能有数据文件

启动数据库
/usr/local/mysql/bin/mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql

修改密码:
方法1:
mysql -u root
grant all privileges on . to root@‘127.0.0.1’ identified by ‘12345’

方法2:
设置数据库密码
dbrootpwd=oneinstack #数据库root密码

/usr/local/mysql/bin/mysql -e “grant all privileges on . to root@‘127.0.0.1’ identified by “oneinstack” with grant option;”
/usr/local/mysql/bin/mysql -e “grant all privileges on . to root@‘localhost’ identified by “$dbrootpwd” with grant option;”

MySQL已经被oracle收购,和MySQL相似的开源数据库叫MariaDB(同一个主宗),我用的二进制版本是MySQL的社区版,你可以在 https://dev.mysql.com/downloads/mysql/ 找到,根据你的操作系统版本,选择对应的源码包或者二进制包。 如果默认的二进制包不能满足你的需求,那你就可以用源码包,选择不同的编译参数,自己编译。 建议:官网上能找到的东西,尽量别百度上随便找。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值