在Linux下部署mysql
1
安装依赖性:
[root@mysql-node10 ~]# dnf install cmake gcc-c++ openssl-devel \ncurses-devel.x86_64 libtirpc-devel-1.3.3-8.el9_4.x86_64.rpm rpcgen.x86_64
2 下载并解压源码包
[root@mysql-node10 ~]# tar zxf mysql-boost-5.7.44.tar.gz[root@mysql-node10 ~]# cd /root/mysql-5.7.44
3
源码编译安装
mysql
[root@mysql-node10 mysql-5.7.44]# cmake \-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \ # 指定安装路径-DMYSQL_DATADIR=/data/mysql \ # 指定数据目录-DMYSQL_UNIX_ADDR=/data/mysql/mysql.sock \ # 指定套接字文件-DWITH_INNOBASE_STORAGE_ENGINE=1 \ # 指定启用 INNODB 存储引擎,默认用 myisam-DWITH_EXTRA_CHARSETS=all \ # 扩展字符集-DDEFAULT_CHARSET=utf8mb4 \ # 指定默认字符集-DDEFAULT_COLLATION=utf8mb4_unicode_ci \ # 指定默认校验字符集-DWITH_BOOST=/root/mysql-5.7.44/boost/boost_1_59_0/ # 指定 c++ 库依赖[root@mysql-node10 mysql-5.7.44]# make -j2 #-j2 表示有几个核心就跑几个进程[root@mysql-node10 mysql-5.7.44# make install
当cmake出错后如果想重新检测,删除 mysql-5.7.44 中 CMakeCache.txt即可
4 部署mysql
#生成启动脚本
[root@node10 ~]# dnf install initscripts-10.11.6-1.el9.x86_64 -y
[root@node10 ~]# cd /usr/local/mysql/support-files/
[root@node10 support-files]# cp mysql.server /etc/init.d/mysqld
#修改环境变量
[root@node10 ~]# vim ~/.bash_profile
export PATH=$PATH:/usr/local/mysql/bin
[root@node10 ~]# source ~/.bash_profile
#生成配置文件
[root@node10 support-files]# yum install mariadb-connector-c-config-3.2.6-
1.el9_0.noarch -y
[root@node10 my.cnf.d]# vim /etc/my.cnf
[mysqld]
datadir=/data/mysql #指定数据目录
socket=/data/mysql/mysql.sock #指定套接字
symbolic-links=0 #数据只能存放到数据目录中,禁止链接到数据目录
#数据库初始化建立mysql基本数据
[root@node10 ~]# mysqld --initialize --user=mysql
[root@node10 ~]# /etc/init.d/mysqld start
[root@node10 ~]# chkconfig mysqld on
#数据库安全初始化
[root@node10 ~]# mysql_secure_installation
Securing the MySQL server deployment.
Enter password for user root: #输入当前密码
生成的启动脚本
创建用户:
修改权限:
修改环境变量:
生成配置文件:
数据库初始化简历mysql基础数据///圈号的是密码
数据库安全初始化
测试:
[root@node10 ~]# mysql -uroot -plee
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 5.7.44 Source distribution
Copyright (c) 2000, 2023, Oracle and/or its affiliates.
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> SHOW DATABASES;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.00 sec)
另外一台主机同上配置好