MYSQL8.0 --- liunx系统安装

linux环境安装

ubutun 系统查看是否安装libaio:dpkg -s libaio

ubutun 系统安装:sudo apt-get install libaio-dev

sudo apt-get install libaio-dev

第一种 :tar包安装

1、官网下载软件包:MySQL :: Download MySQL Community Server (Archived Versions)

2、将软件包放置/usr/local目录下,解压包

xz -d mysql-8.0.32-linux-glibc2.12-x86_64.tar.xz

tar xvf mysql-8.0.32-linux-glibc2.12-x86_64.tar

3、重命名软件包

4、新增用户名和组,授权目录

groupadd mysql

useradd -g mysql mysql

chown -R mysql:mysql /usr/local/mysql/

5、mysql下新建data目录

6、编辑/etc/my.cnf,chmod 640 /etc/my.cnf

[mysqld]
port=3306
user=mysql
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data   #data可设置/opt/mysql/data
socket=/tmp/mysql.sock
log-error=/usr/local/mysql/data/mysql.err
pid-file=/usr/local/mysql/data/mysql.pid
#character config
character_set_server=utf8mb4

7、切换bin下初始化基础信息

./mysqld --defaults-file=/etc/my.cnf --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data  --user=mysql --initialize

如果data 设置其他目录

./mysqld --defaults-file=/etc/my.cnf --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/opt/mysql/data
 

--initialize:会生成随机密码

--intialize-insecure:初始化无密码

生成默认密码

8、添加mysql服务到系统并设置权限

9、添加系统服务并启动数据库,查看数据库状态

chkconfig --add mysql

启动服务

/etc/init.d/mysql start

service mysql start

10、将服务添加到启动PATH目录下

ln -s /usr/local/mysql/bin/mysql /usr/bin/
11、登录数据库,使用上面密码

mysql -u root -p 

12、修改root密码

alter user 'root'@'localhost' identified with mysql_native_password by '123456';

flush privileges;

重置mysql的root密码

1、停止mysql的进程和服务

killall -TERM mysqld”命令停止所有的mysqld进程

service mysql stop

2、进入bin目录,

./mysqld_safe --skip-grant-tables --user=mysql &

3、重新打开新终端,mysql -u root -p 免密进入,设置空格密码

use mysql;

update user set authentication_string = '' where user = 'root';

flush privileges;

4、杀掉启动 --skip-grant-tables的mysql进程

5、启动mysql服务

6、免密登录:mysql -u root -p 

use mysql;

alter user 'root'@'localhost' identified with mysql_native_password by 'root';

错误:ERROR 1396 (HY000): Operation ALTER USER failed for 'root'@'localhost'

解析:查root用,%表示授予root用户的host可以从任何主机的所有权限

                          localhost 标识只能允许本地访问

图中设置%,修改密码改成%

解决办法:

use mysql;

alter user 'root'@'%' identified with mysql_native_password by 'root';

flush privileges;

7、使用新密码正常登录:

错误日志

1、service mysql start  启动服务报错:

mysql: error while loading shared libraries: libtinfo.so.5: cannot open shared object file: No such file or directory

解决办法

ubutun系统:apt-get install install libncurses*

centos系统:yum install libncurses*

2、service mysql start 启动服务报错:mysql :mysql is neither service nor target!? (suse12系统)

解决办法:

systemctl unmask my.service

service mysql start 

3、10060 mysql_mysql错误:Can't connect to MySQL server (10060) 

可能是你的帐号不允许从远程登陆,只能在localhost。登入mysql后,更改 "mysql" 数据库里的 "user" 表里的 "host" 项,从"localhost"改称"%"

解决办法:

use mysql;

update user set host = '%' where user = 'root';

flush privileges;

select host, user from user;

4、连接MySQL出现ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/tmp/mysql.sock

解析:找到mysql.sock文件的位置
一般mysql.sock会在/var/lib/mysql/mysql.sock 或者/var/lib/mysql.sock,一般写到MySQL配置文件 /etc/my.cnf里面,找到sock字段 修改为 /var/lib/mysql/mysql.sock 或/var/lib/mysql.sock
但是MySQL实际是会到/tmp 目录下找mysql.sock 文件。我们可以将var/lib/mysql/mysql.sock 软连接到 /tmp/mysql.sock

解决办法:
ln -s /var/lib/mysql/mysql.sock /tmp/mysql.sock

5、ERROR 1045 (28000): Access denied for user 'root'@'localhost':一般密码错误

6、Warning: World-writable config file '/etc/my.cnf' is ignored
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysqld.sock' 

解析:/etc/my.cnf'权限全局可写,任何一个用户都可以写。mysql担心这种文件被其他用户恶意修改,所以忽略掉这个配置文件。导致无法启动

解决办法:chmod 640 /etc/my.cnf

参考:Linux-安装MySQL(详细教程)_linux安装mysql-CSDN博客

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值