展开
拓展 关闭
订阅号推广码
GitHub
视频
公告栏 关闭

Linux安装jdk、mysql

  • 先安装vim
yum -y install vim*
  • 安装jdk
# 解压
tar -zxvf jdk-8u181-linux-x64.tar.gz
# 移动
mv jdk1.8.0_181/ /usr/local/software/
# 配置
vim /etc/profile
# 配置如下
export JAVA_HOME=/usr/local/software/jdk1.8.0_181
export JRE_HOME=$JAVA_HOME/jre
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JRE_HOME/lib
export PATH=$PATH:$JAVA_HOME/bin
# 生效
source /etc/profile
# 验证
[root@slave1 software]# java -version
java version "1.8.0_181"
Java(TM) SE Runtime Environment (build 1.8.0_181-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.181-b13, mixed mode)
  • 安装mysql
# 解压
tar -zxvf mysql-8.0.34-linux-glibc2.17-x86_64.tar.gz
# 移动
mv /home/mysql-8.0.34-linux-glibc2.17-x86_64/* /usr/local/software/mysql-8.0.34
# 配置
vi /etc/profile
# 配置如下
export MYSQL_HOME=/usr/local/software/mysql-8.0.34
export PATH=$MYSQL_HOME/bin:$PATH
# 生效
source /etc/profile

# 配置my.cnf
vi /usr/local/software/mysql-8.0.34/my.cnf 
# 配置如下
[mysqld]
port=3306
basedir=/usr/local/software/mysql-8.0.34
datadir=/opt/software/mysql-8.0.34/data
pid-file=/usr/local/software/mysql-8.0.34/mysql.pid
socket=/usr/local/software/mysql-8.0.34/mysql.sock
log-error=/usr/local/software/mysql-8.0.34/error.log
server-id=100
# 创建文件和文件夹
mkdir -p /opt/software/mysql-8.0.34/data
touch /usr/local/software/mysql-8.0.34/mysql.pid
touch /usr/local/software/mysql-8.0.34/mysql.sock
touch /usr/local/software/mysql-8.0.34/error.log

# 创建软链接
ln -sf /usr/local/software/mysql-8.0.34/mysql.sock /tmp/mysql.sock
ln -sf /usr/local/software/mysql-8.0.34/my.cnf /etc/my.cnf

# 初始化
mysqld --defaults-file=/usr/local/software/mysql-8.0.34/my.cnf --initialize --user=root --basedir=/usr/local/software/mysql-8.0.34 --datadir=/opt/software/mysql-8.0.34/data
# 查看初始密码为:yknod*I1l7Jb
[root@localhost mysql-8.0.34]# cat /usr/local/software/mysql-8.0.34/error.log | grep password
2023-12-12T19:42:44.030703Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: yknod*I1l7Jb

# 后台启动
[root@localhost mysql-8.0.34]# mysqld_safe --defaults-file=/usr/local/software/mysql-8.0.34/my.cnf --user=root &
[1] 7442
[root@localhost mysql-8.0.34]# 2023-12-12T19:43:53.774441Z mysqld_safe Logging to '/usr/local/software/mysql-8.0.34/error.log'.
2023-12-12T19:43:53.794821Z mysqld_safe Starting mysqld daemon with databases from /opt/software/mysql-8.0.34/data

# 使用Xshell新开1个窗口登录
mysql -uroot -p"yknod*I1l7Jb"
# 修改密码
mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '123456';
Query OK, 0 rows affected (0.01 sec)

# 设置远程登录
# 切换
use mysql;
# 5.7执行如下
grant all privileges on *.* to ‘root‘@‘%‘ identified by ‘123456‘ with grant option
# 8.0执行如下
create user root@'%' identified by '123456';
grant all privileges on *.* to root@'%' with grant option;
# 生效
FLUSH PRIVILEGES;

# 修改锁文件
vi $MYSQL_HOME/support-files/mysql.server
# 注释原来的,添加如下
lockdir="/usr/local/software/mysql-8.0.34"
lock_file_path="$lockdir/mysql.lock"

# 创建软链接
ln -sf /usr/local/software/mysql-8.0.34/my.cnf /etc/my.cnf
ln -sf $MYSQL_HOME/support-files/mysql.server $MYSQL_HOME/bin/mysql.server

# 启动
mysql.server start
# 停止
mysql.server stop
posted @ 2023-12-12 14:03  DogLeftover  阅读(10)  评论(0编辑  收藏  举报