背景
因公司买了国产mips架构服务器,比较小众,MySQL官网大多数都是X86架构安装包,并不提供mips架构现成的安装包,只能使用源码编译进行安装
依赖
依赖什么的因为在 机房是内网环境,无法联网,只能说报什么错就去找什么依赖,我也是这么一步步过来的,因为国产系统你懂的
上传源码包并解压
源码包请 选择自带boost的版本,例如:mysql-boost-5.7.33.tar.gz,我的路径是/opt/softapp/下
tar -zxvf mysql-boost-5.7.33.tar.gz
cd mysql-5.7.33/
编译
cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DSYSCONFDIR=/etc \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DWITH_FEDERATED_STORAGE_ENGINE=1 \
-DWITH_MEMORY_STORAGE_ENGINE=1 \
-DDEFAULT_STORAGE_ENGINE=InnoDB \
-DWITH_SSL=system \
-DWITH_ZLIB=system \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_EMBEDDED_SERVER=1 \
-DENABLE_DOWNLOADS=1 \
-DWITH_EXTRA_CHARSETS=all \
-DWITH_READLINE=1 \
-DWITH_SYSTEMD=1 \
-DWITH_BOOST=/opt/softapp/mysql-5.7.33/boost/boost_1_59_0
创建数据库用户和数据目录
useradd -M -s /sbin/nologin -r mysql
mkdir -p /usr/local/mysql/data
chown -R mysql.mysql /usr/local/mysql/
安装
make
sudo make install
配置文件my.cnf
mv /etc/my.cnf /etc/my.cnf.bak
vim /etc/my.cnf
配置文件的内容
[mysql] default-character-set=utf8 [client] socket=/var/lib/mysql/mysql.sock
[mysqld]
port=3306
user=mysql
general_log = 1
general_log_file= /var/log/mysql/mysql.log
socket=/var/lib/mysql/mysql.sock
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
bind-address = 0.0.0.0
default_storage_engine = InnoDB
character-set-server=utf8
collation-server=utf8_general_ci
lower_case_table_names=1
autocommit=1
symbolic-links=0
skip-networking = 0
log-error=/var/log/mysql/mysql_err.log
pid-file=/var/log/mysql/mysql.pid
配置启动脚本
cd /etc/systemd/system
vim mysqld.service
脚本内容
[Unit]
Description=MySQL DBMS[Service]
LimitNOFILE=10000
Type=simple
User=mysql
Group=mysql
PIDFile=/usr/local/mysql/mysqld.pid
ExecStart=/usr/local/mysql/bin/mysqld --datadir=/usr/local/mysql/data
ExecStop=/bin/kill -9 $MAINPID
[Install]
WantedBy=multi-user.target
添加权限并且设置开机启动
chmod +x mysqld.service
systemctl enable mysqld.service
初始化数据库(空密码,如果需要临时密码,把-insecure参数去掉)
/usr/local/mysql/bin/mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
初始化报错
[root@localhost system]# /usr/local/mysql/bin/mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
2024-07-07T06:24:46.415658Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2024-07-07T06:24:46.433398Z 0 [ERROR] Could not open file '/var/log/mysql/mysql_err.log' for error logging: No such file or directory
2024-07-07T06:24:46.433548Z 0 [ERROR] Aborting
解决:创建文件
mkdir /var/log/mysql
touch /var/log/mysql/mysql_err.log
chown -R mysql:mysql /var/log/mysql
初始化成功
启动MySQL
systemctl start mysqld
登录(无密码,输入密码的时候直接回车即可)
mysql -u root -p
结果(登录成功)
小贴士:
修改密码命令
ALTER USER 'root'@'localhost' IDENTIFIED BY 'your_password';
FLUSH PRIVILEGES;
允许外部连接命令(比如navicat、dbeaver等)
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'your_password' WITH GRANT OPTION;