1.查看是否存在openjdk
java -version
2.如果存在删除openjdk
rpm -qa | grep java
删除所有列表中的所有文件(.noarch后缀的可以不用删除)
rpm -e --nodeps 文件名
3.安装JDK,下载这里就不解释了,自己准备好安装包
创建文件夹
mkdir /usr/local/java/
解压
tar -zxvf jdk-8u311-linux-x64.tar.gz -C /usr/local/java/
4.环境变量
vim /etc/profile
最后一行写入
export JAVA_HOME=/usr/local/java/jdk1.8.0_311 export JRE_HOME=${JAVA_HOME}/jre export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib export PATH=${JAVA_HOME}/bin:$PATH export PATH="$PATH:/usr/local/mysql/bin"
上面为了方便把mysql的先写上,根据需求而定
5.刷新权限
source /etc/profile二.安装Mysql5.7
1.下载安装包,不做演示,很简单,下载完上传到服务器,当然有网的同志可以用wget直接下载
wget https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-5.7.36-el7-x86_64.tar.gz
2.解压安装包
tar -zxvf mysql-5.7.36-el7-x86_64.tar.gz
3.重命名
mv mysql-5.7.36-el7-x86_64 mysql
4.移动安装包
mv mysql /usr/local
5.创建mysql用户组和用户并修改权限
groupadd mysql useradd -r -g mysql mysql
6.创建数据目录并赋予权限
mkdir -p /usr/local/mysql/data chown mysql:mysql -R /usr/local/mysql/data
7.移除mariadb(第一个命令自己看版本移除)
rpm -qa | grep mariadb rpm -e mariadb-libs-5.5.68-1.el7.x86_64 --nodeps
8.创建my.cnf
vi /etc/my.cnf
复制进去以下内容
[mysqld] #端口号 port = 3306 #mysql-5.7.36文件的路径 basedir=/usr/local/mysql #mysql-5.7.36数据路径 datadir=/usr/local/mysql/data log-error=/usr/local/mysql/data/mysql.err #最大连接数 max_connections=600 #编码 character-set-server=utf8 #skip-grant-tables default-storage-engine=INNODB #不区分大小写 lower_case_table_names=1 #绑定ipv4 bind-address=0.0.0.0 #设置传输包限制,默认1M max_allowed_packet=64M #设置缓冲池大小: innodb_buffer_pool_size=1024M #设置隔离级别 transaction-isolation=read-committed #设置时区 default-time-zone='+8:00' #设置密码验证默认加密方式 #default-authentication-plugin=mysql_native_password explicit_defaults_for_timestamp=true [mysql] #编码 default-character-set=utf8
10.初始化数据库
cd /usr/local/mysql/bin ./mysqld --defaults-file=/etc/my.cnf --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/ --user=mysql --initialize
11.如果上面报错说缺少libaio(没网自己离线下载吧)
下载地址:wget https://repo.almalinux.org/almalinux/8/baseOS/x86_64/os/Packages/libaio-0.3.112-1.el8.x86_64.rpm
安装:rpm -ivh libaio-0.3.112-1.el8.x86_64.rpm
返回第十步
12.查看root密码
[root@shigj bin]# cat /usr/local/mysql/data/mysql.err 2021-11-10T08:45:20.242160Z 0 [Warning] InnoDB: New log files created, LSN=45790 2021-11-10T08:45:20.288796Z 0 [Warning] InnoDB: Creating foreign key constraint system tables. 2021-11-10T08:45:20.346361Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 895b2959-4202-11ec-8dae-00163e03473d. 2021-11-10T08:45:20.347667Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened. 2021-11-10T08:45:21.167981Z 0 [Warning] A deprecated TLS version TLSv1 is enabled. Please use TLSv1.2 or higher. 2021-11-10T08:45:21.167993Z 0 [Warning] A deprecated TLS version TLSv1.1 is enabled. Please use TLSv1.2 or higher. 2021-11-10T08:45:21.168567Z 0 [Warning] CA certificate ca.pem is self signed. 2021-11-10T08:45:21.811242Z 1 [Note] A temporary password is generated for root@localhost: egFw0x=%-E/e
一般在最后一行
13.设置服务
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql /etc/init.d/mysql start service mysql restart
14.设置环境变量(上面java设置过的就不用设置了)
vi /etc/profile 放在文件最后一行 export PATH="$PATH:/usr/local/mysql/bin" 生效 source /etc/profile
15.进入mysql
mysql -uroot -p 输入密码
16.更改密码
SET PASSWORD = PASSWORd('12345678'); ALTER USER 'root'@'localhost' PASSWORD EXPIRE NEVER; FLUSH PRIVILEGES;
17.修改远程
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 host = '%' where user = 'root'; Query OK, 1 row affected (0.00 sec) Rows matched: 1 Changed: 1 Warnings: 0 mysql> FLUSH PRIVILEGES; Query OK, 0 rows affected (0.00 sec) mysql> exit; Bye
18.设置开机启动
chkconfig --list 查看列表 chkconfig add mysql 添加 chkconfig mysql on 设置开机自启动
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)