• 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏吧

源码安装MySql5.7到Centos

互联网 diligentman 2周前 (11-20) 10次浏览

一、下载

下载地址: https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-boost-5.7.25.tar.gz

二、添加用户

useradd -s /sbin/nologin mysql

三、创建目录并授权

mkdir -p /data/mysql/data
mkdir -p /usr/local/mysql
chown -R mysql:mysql /data/mysql

四、解压并安装

# 解压
tar -zxvf mysql-boost-5.7.25.tar.gz -C /usr/local/mysql/
# 进入安装文件目录
cd /usr/local/mysql/mysql-5.7.25/
# 编译并安装
cmake -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_BOOST=boost
make && make install

五、创建配置文件

vim /etc/my.cnf

在该文件中写入,配置文件根据自己的需求做调整即可,下面是一个示例:

[client]
port        = 3306
socket      = /tmp/mysql.sock

[mysqld]
port        = 3306
socket      = /tmp/mysql.sock
user = mysql


basedir = /usr/local/mysql
datadir = /data/mysql/data
pid-file = /data/mysql/mysql.pid

log_error = /data/mysql/mysql-error.log
slow_query_log = 1
long_query_time = 1
slow_query_log_file = /data/mysql/mysql-slow.log


skip-external-locking
key_buffer_size = 32M
max_allowed_packet = 1024M
table_open_cache = 128
sort_buffer_size = 768K
net_buffer_length = 8K
read_buffer_size = 768K
read_rnd_buffer_size = 512K
myisam_sort_buffer_size = 8M
thread_cache_size = 16
query_cache_size = 16M
tmp_table_size = 32M
performance_schema_max_table_instances = 1000

explicit_defaults_for_timestamp = true
#skip-networking
max_connections = 500
max_connect_errors = 100
open_files_limit = 65535

log_bin=mysql-bin
binlog_format=mixed
server_id   = 232
expire_logs_days = 10
early-plugin-load = ""

default_storage_engine = InnoDB
innodb_file_per_table = 1
innodb_buffer_pool_size = 128M
innodb_log_file_size = 32M
innodb_log_buffer_size = 8M
innodb_flush_log_at_trx_commit = 1
innodb_lock_wait_timeout = 50

[mysqldump]
quick
max_allowed_packet = 16M

[mysql]
no-auto-rehash

[myisamchk]
key_buffer_size = 32M
sort_buffer_size = 768K
read_buffer = 2M
write_buffer = 2M

六、授权并初始化

cd /usr/local/mysql/bin
chown -R mysql:mysql mysql
./mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql/data

/data/mysql/data文件夹必须是空的

七、拷贝可执行文件

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

八、启动mysql

# 启动
service mysqld start
# 设置开机自动启动
systemctl enable mysqld

九、设置环境变量

vi /etc/profile

#在/etc/profile里加入
PATH=/usr/local/mysql/bin:$PATH

source /etc/profile

十、测试

# 默认没有密码
mysql -hlocalhost -uroot -p

十一、设置密码

# 链接到mysql后执行
mysql> set password for 用户名@localhost = password('新密码'); 

十二、设置远程访问

GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '密码'  
flush privileges;

 


喜欢 (0)