mysql 编译安装

1 首先去官网下载源码安装包,这个问度娘即可。

2 mysql 从5.5版本以上编译安装采用cmake的方式,首先安装cmake,可以源码和yum安装。我这里比较简单就使用yum了

yum -y install make gcc-c++ cmake bison-devel ncurses-devel

创建mysql用户及组

groupadd mysql

useradd -g mysql mysql -s /usr/sbin/nologin

创建mysql的安装目录

mkdir /data/mysql

cd /data/mysql

mkdir log
mkdir data

3 解压mysql 安装

tar -zxvf mysql-5.6.35.tar.gz

cmake .  -DCMAKE_INSTALL_PREFIX=/data/mysql -DMYSQL_DATADIR=/data/mysql/data -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci  -DEXTRA_CHARSETS=all  -DENABLED_LOCAL_INFILE=1

make
make install

这个编译安装时间比较慢,耐心等待,中间假如出现错误,根据错误解决。


编辑my.cnf ---我这里就简单写了下,具体参数根据自己服务器和业务设定

[mysqld]
port = 3306
datadir = /data/mysql/data
basedir = /data/mysql
log_error = /data/mysql/log/error.log
pid-file=/data/mysql/data/mysqld.pid
#skip-grant-tables
socket=/tmp/mysql.sock
server-id=2
log-bin=mysql-bin
expire_logs_days=8

#mysql优化参数
#linux默认对数据库表大小写敏感,设置为1,自动都转换成小写
lower_case_table_names = 1
# 数据库异常连接超过次数,拒绝连接,建议大于10
max_connect_errors = 500
#服务器关闭交互式连接所等待的秒数
interactive_timeout=172800
#服务器关闭非交互式连接所等待的秒数
wait_timeout=172800
#只读为主的业务应用场景
#transaction-isolation=read-commited
#binlog-format=mixed
#非只读为主的业务应用场景
#transaction-isolation=repeatabled-read
binlog-format=mixed 
#InnoDB引擎会根据数据的访问频繁度,把表的数据逐渐缓到内存,HASH Index 会更高效
#innodb_adaptive_hash_index= ON
#Dirty_Page在Buffer_Pool中所占的比率建议设置为5%~90%
#innodb_max_dirty_pages_pct= 75
#同一时刻,允许多少个线程同时提交InnoDB事务,默认值为0
#innodb_commit_concurrency=0
#设置innodb引擎关闭的方式,默认值为:1,正常关闭的状态
#innodb_fast_shutdown = 1
#mysqld服务出现崩溃之后,InnoDB引擎进行回滚的模式,默认值为0,可设置的值0~6
#innodb_force_recovery =0
#开辟一片内存用于缓存InnoDB引擎的数据字典信息和内部数据结构,build-in版本默认值为:1M;Plugin-innodb版本默认值为:8M;
#innodb_additional_mem_pool_size=32M
#用于缓存InnoDB引擎表的数据和索引,命中率97%以上
innodb_buffer_pool_size= 512M
#把事务日志缓存区的数据写到日志文件中,以及把日志文件的数据刷新到磁盘上
#innodb_flush_log_at_trx_commit=1
#sync_binlog = 0
#每个表一个表空间
#innodb_file_per_table=1
#索引缓存区推荐:64M
key_buffer_size = 64M
#查询缓存的功能 写入量或是更新量大可禁用
#query_cache_size = 32M
#query_cache_type = 0
[client]
default_character_set=utf8
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES


创建数据库

cd /data/mysql/scripts

./mysql_install_db --user=mysql --basedir=/data/mysql --datadir=/data/mysql/data

5.启动命令
/data/mysql/bin/mysqld_safe --defaults-file=/data/mysql/my.cnf &

启动后进行安全设置

/data/mysql/bin/mysql_secure_installation

初始root密码为空

[root@upgrade mysql]#  /data/mysql/bin/mysql_secure_installation
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!
In order to log into MySQL to secure it, we'll need the current
password for the root user.  If you've just installed MySQL, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none): 
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MySQL
root user without the proper authorisation.

Set root password? [Y/n] y
New password: 
Re-enter new password: 
Password updated successfully!
Reloading privilege tables..
 ... Success!

By default, a MySQL installation has an anonymous user, allowing anyone
to log into MySQL without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] y
 ... Success!

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] y
 ... Success!

By default, MySQL comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] y
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.


Reload privilege tables now? [Y/n] y
 ... Success!



All done!  If you've completed all of the above steps, your MySQL
installation should now be secure.

Thanks for using MySQL!

Cleaning up...



9、配置启动脚本

cd /data/mysql/support-files/
cp mysql.server /etc/init.d/mysqld

chmod 700 /etc/init.d/mysqld
chkconfig --add mysqld
/etc/init.d/mysqld restart
service mysqld restart

10 root密码忘记

启动 增加 skip-grant-tables,

update mysql.user  set password=password('newpassword') where user='root'


11 链接mysql命令到默认环境变量

ln -s /data/mysql/bin/mysql* /usr/bin/


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值