登录
首页 >  数据库 >  MySQL

Linux下MySQL编译安装及初始化

来源:SegmentFault

时间:2023-02-24 12:26:57 195浏览 收藏

大家好,今天本人给大家带来文章《Linux下MySQL编译安装及初始化》,文中内容主要涉及到MySQL、Linux,如果你对数据库方面的知识点感兴趣,那就请各位朋友继续看下去吧~希望能真正帮到你们,谢谢!

环境

操作系统:CentoOS 6.7 x64
御马安装包:/opt/mysql-5.6.29.tar.gz
MySQL安装目录:/opt/yliyun/mysql

第一步 安装编译所需依赖

yum -y install wget bison gcc gcc-c++ autoconf automake zlib* libxml* ncurses-devel libtool-ltdl-devel* cmake make

第二步 解压

cd /opt
tar zxf mysql-5.6.29.tar.gz

第三步 编译安装

cd /opt/mysql-5.6.29

cmake . \
-DCMAKE_INSTALL_PREFIX=/opt/yliyun/mysql \
-DMYSQL_DATADIR=/opt/yliyun/mysql/data \
-DINSTALL_LIBDIR=/opt/yliyun/mysql/lib \
-DINSTALL_PLUGINDIR=/opt/yliyun/mysql/plugin \
-DMYSQL_UNIX_ADDR=/opt/yliyun/mysql/data/mysql.sock \
-DSYSCONFDIR=/opt/yliyun/mysql/etc \
-DMYSQL_USER=root \
-DMYSQL_TCP_PORT=3306 \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_INNOBASE_STORAGE_ENGINE=1 

make

make install

第四步 初始化数据库

cd /opt/yliyun/mysql
scripts/mysql_install_db --user=root --datadir=/opt/yliyun/mysql/data

第五步 默认配置文件my.cnf

mkdir -pv /opt/yliyun/mysql/etc
cp -f /opt/yliyun/mysql/support-files/my-default.cnf /opt/yliyun/mysql/etc/my.cnf

修改 /opt/yliyun/mysql/etc/my.cnf内容,部分修改如下:

[mysqld]

 innodb_buffer_pool_size = 128M

 log_bin=mysql-bin

 expire-logs-days=30
 binlog-do-db=yliyun
 binlog-do-db=yliyun_log
 binlog-ignore-db=test

 basedir = /opt/yliyun/mysql
 datadir = /opt/yliyun/mysql/data
 port = 3306
 server_id = 1
 socket = /opt/yliyun/mysql/data/mysql.sock
 user = root

 join_buffer_size = 128M
 sort_buffer_size = 2M
 read_rnd_buffer_size = 2M 

 key_buffer_size = 16M
 max_allowed_packet = 8M
 table_open_cache = 64
 skip-name-resolve

 innodb_file_per_table = 1

 innodb_log_file_size = 16M
 innodb_log_buffer_size = 4M

 slow_query_log_file = /opt/yliyun/mysql/logs/slowquery.log
 slow_query_log = 1
 long_query_time = 1

sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

[mysqld_safe]
log-error=/opt/yliyun/mysql/logs/mysql-error.log
                                                                                               

第六步 配置开机启动

mkdir -pv /var/lock/subsys/mysql
cp -f /opt/yliyun/mysql/support-files/mysql.server /etc/rc.d/init.d/mysqld

修改/etc/rc.d/init.d/mysqld中如下内容:

basedir=/opt/yliyun/mysql
datadir=$basedir/data

mysqld_pid_file_path="$datadir/mysql.pid"

配置开机启动

chmod 755 /etc/rc.d/init.d/mysqld
chkconfig --add mysqld
service mysqld start

第七步 设置root管理员密码

/opt/yliyun/mysql/bin/mysqladmin -u root password "root密码"

第八步 删除空密码账户

mysql/bin/mysql -uroot -p -e "use mysql; delete from user where password='';"

今天带大家了解了MySQL、Linux的相关知识,希望对你有所帮助;关于数据库的技术知识我们会一点点深入介绍,欢迎大家关注golang学习网公众号,一起学习编程~

声明:本文转载于:SegmentFault 如有侵犯,请联系study_golang@163.com删除
相关阅读
更多>
最新阅读
更多>
课程推荐
更多>