龙蜥操作系统
Anolis OS 8 是 OpenAnolis 社区推出的完全开源、中立、开放的发行版,它支持多计算架构,也面向云端场景优化,兼容 CentOS 软件生态。Anolis OS 8 旨在为广大开发者和运维人员提供稳定、高性能、安全、可靠、开源的操作系统服务。
Apache Tomcat官网: Anolis系统中离线安装Tomcat与Linux一致,Tomcat下载到本地,上传解压运行即可。
MySql官网
Anolis系统中离线安装MySql数据库,与Linux安装方式基本一致。
安装版本:mysql-5.7.26-linux-glibc2.12-x86_64.tar.gz
进入安装流程
创建目录
mkdir -p /server/tools
mkdir -p /opt/mysql
mkdir -p /data/mysql/mysql3306/{data,logs}
cd /server/tools #进入到该目录
解压安装包
tar zxf mysql-5.7.26-linux-glibc2.12-x86_64.tar.gz
移动到指定目录
mv mysql-5.7.26-linux-glibc2.12-x86_64 /opt/mysql/mysql-5.7.26
创建软连接
ln -s /opt/mysql/mysql-5.7.26/ /usr/local/mysql
编辑配置文件
vi /data/mysql/mysql3306/my3306.cnf
[client]
user=mysql
port= 3306
socket= /data/mysql/mysql3306/mysql.sock
[mysqld]
port= 3306
user=mysql
server_id= 1
basedir=/usr/local/mysql
datadir=/data/mysql/mysql3306/data
log_error=/data/mysql/mysql3306/logs/error.log
log_bin=/data/mysql/mysql3306/logs/mysql-bin
binlog_format=row
gtid_mode=on
enforce_gtid_consistency=true
log_slave_updates=1
max_connections=1024
wait_timeout=60
sort_buffer_size=2M
max_allowed_packet=32M
join_buffer_size=2M
innodb_buffer_pool_size=128M
innodb_flush_log_at_trx_commit=1
innodb_log_buffer_size=32M
innodb_log_file_size=128M
innodb_log_files_in_group=2
binlog_cache_size=2M
max_binlog_cache_size=8M
max_binlog_size=512M
expire_logs_days=7
slow_query_log=on
slow_query_log_file=/data/mysql/mysql3306/logs/slow.log
long_query_time=0.5
log_queries_not_using_indexes=1
初始化数据库
初始化数据库之前如果/data/mysql/mysql3306路径下有data文件夹,则需要删除,否则初始化失败。
/usr/local/mysql/bin/mysqld --defaults-file=/data/mysql/mysql3306/my3306.cnf --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql/mysql3306/data
加入环境变量
vim /etc/profile #vim编辑
export PATH="/usr/local/mysql/bin:$PATH"
启动数据库
mysqld --defaults-file=/data/mysql/mysql3306/my3306.cnf &
查看是否启动成功
netstat -lntup
启动数据库报错
2025-01-13T09:19:04.303142Z 0 [ERROR] Fatal error: Can't open and lock privilege tables: Table 'mysql.user' doesn't exist
2025-01-13T09:19:04.303159Z 0 [ERROR] Fatal error: Failed to initialize ACL/grant/time zones structures or failed to remove temporary table files.
解决报错
vim /etc/my.cnf
datadir=/var/lib/mysql/data删除data目录中的内容
rm -rf data //在mysql安装目录下执行
mkdir data
连接数据库
因为初始化的时候设置了–initialize-insecure,所以登录时不需要密码。
第一次连接没有密码,直接敲回车:mysql -u root -p
存在问题
启动数据库时只能使用:mysqld --defaults-file=/data/mysql/mysql3306/my3306.cnf &
不能使用用:service mysqld start
命令,使用该命令会报如下错误:
Starting MySQL.Logging to '/usr/local/mysql/data/anolis.err'.ERROR! The server quit without updating PID file (/usr/local/mysql/data/anolis.pid).
解决办法
- 将配置文件移动到mysql的安装目录
- 修改配置文件中的路径
- 设置通过命令启动:
mv /opt/mysql/mysql-5.7.26/support-files/mysql.server /etc/init.d/mysqld
- 设置用户权限
# 增加用户和组
[root@anolis ~]# groupadd mysql
[root@anolis ~]# useradd -r -g mysql mysql
# 设置对应的mysql文件权限
# 这里因为/usr/local/mysql/data是创建的/opt/mysql/mysql-5.7.26/的软链接,所以两个地址实际上是一个
chown mysql:mysql -R /opt/mysql/mysql-5.7.26/
chmod -R 755 /usr/local/mysql/data
- 初始化数据库
# 进入mysql安装目录
cd /usr/local/mysql/data
# 删除data
rm -rf data/
# 初始化,如果是--initialize的话登录就需要输入密码
./bin/mysqld --defaults-file=/usr/local/mysql/my.cnf --initialize-insecure --user=mysql
# 初始化完成后可进行启动数据库
[root@anolis mysql]# service mysqld restartERROR! MySQL server PID file could not be found!
Starting MySQL.. SUCCESS!
登录数据库
[root@anolis mysql]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.26-log MySQL Community Server (GPL)Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -ADatabase changed
# 设置数据库密码
mysql> update user set authentication_string=password("数据库密码") where user="root";
Query OK, 1 row affected, 1 warning (0.02 sec)
Rows matched: 1 Changed: 1 Warnings: 1
# 刷新,否则可能不生效
mysql> flush privileges;
Query OK, 0 rows affected (0.05 sec)
# 设置数据库远程访问
mysql> update user set host='%' where user='root';
Query OK, 1 row affected (0.02 sec)
Rows matched: 1 Changed: 1 Warnings: 0
# 刷新
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
# 退出
mysql> quit;Bye
设置MySQL开机自启
设置MySQL开机自启可以通过chkconfig命令来实现
# 添加到管理列表
chkconfig --add mysqld
# 设置开机自启动,或者通过chkconfig --level 2345 mysql on命令来指定在运行级2、3、4、5中开启MySQL服务
chkconfig mysqld on
# 查看设置状态
chkconfig --list mysqld
[root@anolis ~]# chkconfig --list mysqld
Note: This output shows SysV services only and does not include nativesystemd services. SysV configuration data might be overridden by nativesystemd configuration.If you want to list systemd services use 'systemctl list-unit-files'.To see services enabled on particular target use'systemctl list-dependencies [target]'.mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off