Linux Mysql8.0安装教程

2.解压并重命名
[root@rsyncClient local]# tar -zxvf mysql-8.0.18-el7-x86_64.tar.gz -C /usr/local/

[root@rsyncClient local]# mv mysql-8.0.18-el7-x86_64/ mysql
3.在mysql根目录下创建data目录,存放数据
[root@rsyncClientopt]# cd /usr/local/mysql/

[root@rsyncClient mysql]# mkdir data
4.创建mysql用户组和mysql用户
[root@rsyncClient local]# groupadd mysql

[root@rsyncClient local]# useradd -g mysql mysql
5.改变mysql目录权限
[root@rsyncClient local]# chown -R mysql.mysql /usr/local/mysql/
6.初始化数据库
[root@rsyncClient mysql]# bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql
–datadir=/usr/local/mysql/data

7.配置mysql
在mysql/support-files创建文件my-default.cnf
[root@rsyncClient support-files]# cd /usr/local/mysql/support-files/
[root@rsyncClient support-files]# touch my-default.cnf
吃的复制配置文件到/etc/my.cnf
[root@rsyncClient support-files]# cp -a ./my-default.cnf /etc/my.cnf
cp: overwrite ‘/etc/my.cnf’? y
编辑my.cnf

[client]
port=3306
socket=/tmp/mysql.sock

[mysqld]
port=3306
user=mysql
socket=/tmp/mysql.sock
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data

8.配置环境变量
编辑 / etc/profile 文件

[root@rsyncClient mysql]# vim /etc/profile
#配置mysql环境变量
PATH=/data/mysql/bin:/data/mysql/lib:$PATH
export PATH
#让其生效
[root@rsyncClient mysql]# source /etc/profile
#看环境变量是否生效
[root@rsyncClient mysql]# echo $PATH/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin

9.开机自启,进入/usr/local/mysql/support-files进行设置
1
2
3 # cd support-files/

cp mysql.server /etc/init.d/mysql

chmod +x /etc/init.d/mysql

10.注册服务
1 # chkconfig --add mysql
查看 —> chkconfig --list mysql

9.启动mysql
[root@rsyncClient mysql]# systemctl start mysqld
启动失败报错1:
Job for mysql.service failed because the control process exited with error code. See “systemctl status mysql.service” and “journalctl -xe” for details.
解决方案:
[root@rsyncClient ~]# chown mysql:mysql -R /usr/local/mysql/
启动失败报错2:
[root@rsyncClient mysql]# service mysql start/etc/init.d/mysql: ./bin/my_print_defaults: /lib/ld-linux.so.2: bad ELF interpreter: No such file or
directory Starting MySQL. ERROR! The server quit without
updating PID file (/var/lib/mysql/rsyncClient.pid).
去这个目录下面查看 cat/usr/local/mysql/data/rsyncClient.err错误,对应的的解决,这里错误是因为my.conf配置错误
 启动失败报错3:
mysql: error while loading shared libraries: libncurses.so.5: cannot open shared object file:
No such file or directory
[root@rsyncClient init.d]# yum install libncurses.so.5
以这个为例,如果缺少这样依赖,直接用yum安装
启动失败报错4:
[root@rsyncClient data]# mysql -uroot -p
Enter password:
ERROR 2059 (HY000): Authentication plugin ‘caching_sha2_password’ cannot be loaded:
/usr/lib/mysql/plugin/caching_sha2_password.so: cannot open shared object file: No such file or directory
身份验证插件不能加载
解决办法:
[root@rsyncClient lib]# vim /etc/my.cnf
在这个[mysqld]下添加一行:
default_authentication_plugin=mysql_native_password
如果忘记了密码在加上:
skip-grant-tables(跳过密码验证)等设置了密码就去掉
10 使用systemctl命令启动关闭mysql服务

启动mysql服务:

#systemctl start mysqld.service

停止mysql服务

#systemctl stop mysqld.service

重启mysql服务

#systemctl restart mysqld.service

查看mysql服务当前状态

#systemctl status mysqld.service

设置mysql服务开机自启动

#systemctl enable mysqld.service

停止mysql服务开机自启动

#systemctl disable mysqld.service

11.mysql的基本操作

使用mysql客户端连接mysql

/usr/local/mysql/bin/mysql -u root -p password
修改mysql的默认初始化密码
alter user ‘root’@‘localhost’ identified by ‘Twm2020’;

创建用户 CREATE USER ‘用户名称’@‘主机名称’ INDENTIFIED BY ‘用户密码’

create user ‘yehui’@‘localhost’ identified by ‘yehui’;
#给所有远程登录的进行授权,此方式已经报错了

修改root用户可以远程连接

update mysql.user set host=‘%’ where user=‘root’;
 ALTER USER ‘root’@‘%’ IDENTIFIED WITH mysql_native_password BY ‘new password’;
#刷新
flush privileges;
#权限问题可以参考https://www.cnblogs.com/php-linux/p/11561300.html

12.防火墙问题
[root@rsyncClient data]# firewall-cmd --permanent --zone=public --add-port=3306/tcp #允许访问
---->success
[root@rsyncClient data]# firewall-cmd --reload #重新加载
---->success
[root@rsyncClient data]# firewall-cmd --permanent --zone=public --query-port=3306/tcp  #查看是否开通访问权限
---->yes

PS: 软链接
查看: /etc/bin

1.新建—>ln -s 【目标目录】 【软链接地址】 例:  ln -s  /usr/local/mysql/bin/mysql    /usr/bin
2.删除 —>rm -rf 【软链接地址】
3.修改 ----> ln -snf 【新目标目录】 【软链接地址】

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值