公司要求不让用兄弟公司的基础服务,因为用他们的服务必须都走他们的发布系统,由于公司已经分家,暂时节约成本,所以要求在空闲的服务器搭建mysql,redis等服务,好在我们的服务器都是64g内存,40核的机器,空间也够大。兄弟公司说我们现在的体量问题不大,那就自己来吧。

开搞

准备配置文件并copy到/etc/my.cnf

https://downloads.mysql.com/archives/community/

https://dev.mysql.com/doc/refman/5.7/en/binary-installation.html

ubuntu apt安装的mysql 配置 做参考

 1[client]
 2port = 3306
 3socket = /var/run/mysqld/mysqld.sock
 4default-character-set = utf8mb4 #编码
 5
 6[mysqld_safe]
 7socket          = /var/run/mysqld/mysqld.sock
 8nice            = 0
 9
10[mysqld]
11user            = mysql
12pid-file        = /var/run/mysqld/mysqld.pid
13socket          = /var/run/mysqld/mysqld.sock
14port            = 3306
15basedir         = /usr
16datadir         = /var/lib/mysql
17tmpdir          = /tmp
18lc-messages-dir = /usr/share/mysql
19skip-external-locking
20skip-name-resolve
21bind-address            = 0.0.0.0
22key_buffer_size         = 16M
23max_allowed_packet      = 16M
24thread_stack            = 192K
25thread_cache_size       = 8
26myisam-recover-options  = BACKUP
27query_cache_limit       = 1M
28query_cache_size        = 16M
29log_error = /var/log/mysql/error.log
30#server-id              = 1
31#log_bin                        = /var/log/mysql/mysql-bin.log
32expire_logs_days        = 10
33max_binlog_size   = 100M
34character-set-server = utf8mb4 #编码

my.cnf 配置 cp 到 /etc/my.cnf

https://github.com/cr-mao/develop/blob/main/mysql/my.cnf

初始化配置目录,开始安装

 1sudo mkdir -p /var/run/mysql /db/data /db/tmp /db/logs/
 2# 安装依赖
 3sudo apt-cache search libaio # search for info  
 4sudo apt-get install libaio1 # install library
 5sudo wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.35-linux-glibc2.12-x86_64.tar.gz
 6sudo tar zxvf mysql-5.7.35-linux-glibc2.12-x86_64.tar.gz 
 7sudo mv mysql-5.7.35-linux-glibc2.12-x86_64 /usr/local/mysql
 8sudo groupadd mysql
 9sudo useradd -r -g mysql -s /bin/false mysql
10sudo chown -R mysql:mysql /db
11cd /usr/local/mysql
12sudo mkdir mysql-files
13sudo chown mysql:mysql mysql-files
14sudo chmod 750 mysql-files
15# 初始化数据,及密码 
16sudo /usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnf --basedir=/usr/local/mysql/ --datadir=/db/data --user=mysql --initialize
17
18# 密码 cat /db/logs/mysql-error.log 获得   uhk,lZgFu1W5 
19
20
21sudo  cp support-files/mysql.server /etc/init.d/mysql.server # 默认的不行,mysqld-safe 执行文件是不对的, 做了下修改

Mysql.server 文件修改

https://github.com/cr-mao/develop/blob/main/mysql/mysql.server

1sudo systemctl start mysql 

执行文件加到环境变量

1echo 'PATH=$PATH:/usr/local/mysql/bin' >> ~/.bashrc
2echo 'export PATH'  >> ~/.bashrc
3source ~/.bashrc

修改密码,授权用户

1xxxx@xxx:/usr/local/mysql/support-files$ ps -ef | grep mysql
2root     14445     1  0 07:58 pts/0    00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/usr/local/mysql/data --pid-file=/usr/local/mysql/logs/mysqld.pidmysql    19098 14445  1 08:05 pts/0    00:00:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/usr/local/mysql/logs/mysqld.log --pid-file=/usr/local/mysql/logs/mysqld.pid --socket=/tmp/mysql.sock --port=3307
3 # 有2个进程,  启动mysqld_safe是监控进程 拉起mysqld作用 ,mysqld_safe 是nice=0的高优先级进程
4 
5 #登录进去修改密码
6set password=password("your password");
7flush privileges;
1grant all on *.* to youadminaccount@'%' identified by 'yourpassword' with grant option;
2grant all on `database_name`.* to youadminaccount@'%' identified by 'yourpassword' with grant option;
3flush privileges;
4select user,host from mysql.user \G;