1.下载安装包:
官方下载地址:点我!点我!!!
2.上传linux解压安装:
1.通过Xftp上传:
- 解压:
tar -xvf mysql-8.0.23-linux-glibc2.12-x86_64.tar.xz
- 移动到usr/local目录下,并重命名:
mv mysql-8.0.23-linux-glibc2.12-x86_64 /usr/local/mysql
- 在mysql根目录下新建一个文件夹data,用于存放数据:
mkdir data
- 创建 mysql 用户组和 mysql 用户:
//创建mysql用户组
groupadd mysql
//创建mysql用户
useradd -g mysql mysql
- 改变 mysql 目录权限:
chown -R mysql.mysql /usr/local/mysql/
- 初始化数据库:
//创建mysql_install_db安装文件
mkdir mysql_install_db
chmod 777 ./mysql_install_db
//初始化
/usr/local/mysql/bin/mysqld --initialize --user=mysql
2021-04-16T12:21:59.309051Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2021-04-16T12:22:01.177374Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2021-04-16T12:22:03.955009Z 6 [Note] [MY-010454] [Server] A temporary password is generated
for root@localhost: Uvy2fwkYp5#O
记录临时密码:Uvy2fwkYp5#O
- mysql配置
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
修改my.cnf文件
vim /etc/my.cnf
[mysqld]
basedir = /usr/local/mysql
datadir = /usr/local/mysql/data
socket = /usr/local/mysql/mysql.sock
character-set-server=utf8
port = 3306
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
[client]
socket = /usr/local/mysql/mysql.sock
default-character-set=utf8
- 建立MySQL服务
cp -a ./support-files/mysql.server /etc/init.d/mysqld
chmod +x /etc/rc.d/init.d/mysqld
//添加到服务器
chkconfig --add mysqld
//检查服务是否生效
chkconfig --list mysqld
步骤无误则出现如下界面:
[root@VM-0-6-centos mysql]# chkconfig --list mysqld
Note: This output shows SysV services only and does not include native
systemd services. SysV configuration data might be overridden by native
systemd 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
- 配置全局环境变量
//编辑 /etc/profile 文件
vi /etc/profile
//在 profile 文件底部添加如下两行配置
export PATH=$PATH:/usr/local/mysql/bin:/usr/local/mysql/lib
export PATH
//设置环境变量立即生效
source /etc/profile
- 启动MySQL服务
//启动mysql服务
service mysql start
- 登录MySQL
//登录命令
mysql -uroot -p
//修改密码
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '123456';
- 设置可以远程登录
mysql>use mysql
mysql>update user set host='%' where user='root' limit 1;
//刷新权限
mysql>flush privileges;
检查3306端口是否开放
netstat -tnl |grep 3306
端口未开放时,应将其打开
参考文章:https://blog.csdn.net/github_39533414/article/details/80144890
数据库操作相关命令可参考:https://blog.csdn.net/smile_Running/article/details/88686976
自己先给自己点个赞,冲啊!咱是最棒的!嘿嘿!观看的小可爱一起点个赞呗,求求了!