1.下载mysql
wget https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-8.0.13-linux-glibc2.12-x86_64.tar
2.解压mysql包
tar -xvf mysql-8.0.13-linux-glibc2.12-x86_64.tar
再解压
tar xvJf mysql-8.0.13-linux-glibc2.12-x86_64.tar.xz
修改名称
mv mysql-8.0.13-linux-glibc2.12-x86_64 mysql
3.安装mysql
3.1 增加mysql用户
创建mysql用户组:groupadd mysql
创建mysql用户:useradd -g mysql mysql
设置密码:passwd mysql
3.2添加默认配置文件
vim/etc/my.cnf
[client]
port=3306
socket=/tmp/mysql/mysql.sock
[mysqld]
port=3306
user=mysql
socket=/tmp/mysql/mysql.sock
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
log-error=error.log
3.3 初始化mysql
/usr/local/mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/
可能遇到错误:
提示没有权限/tmp/mysql,解决方案,执行命令:chown -R mysql:mysql /tmp/mysql
提示error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory,解决方案,安装libaio 即可yum install -y libaio
如果无异常情况日志如下可以看到mysql默认会生成root账号和密码
3.4 启动mysql服务器
./support-files/mysql.server start
4.创建myslq用户
创建用户:create user ‘jack‘@‘localhost‘ identified by ‘jack‘;
授予权限:grant replication slave on *.* to ‘jack‘@‘localhost‘;
刷新:flush privileges;
5.mysql忘记密码重置
免密码登陆,vim /etc/my.cnf,在【mysqld】模块添加:skip-grant-tables
重启mysql服务: service mysqld restart
登陆mysql,mysql -u root -p //提示输入密码时直接敲回车
选择mysql数据库,use mysql
将root密码置空,update user set authentication_string = ‘‘ where user = ‘root‘;
去重my.cnf中的skip-grant-tables并重启mysql服务
登陆mysql选择数据库修改密码,ALTER USER ‘root‘@‘localhost‘ IDENTIFIED BY ‘password‘;(注意,这里mysql默认加密用的sha,navicat连接会提示authentication plugin ‘caching_sha2_password‘,可使用ALTER USER ‘root‘@‘localhost‘ IDENTIFIED WITH mysql_native_password BY ‘password‘;
是mysql配置立即生效flush privileges;
6.其它问题
6.1 linux下执行mysql 命令提示unknown
原因:这是由于系统默认会查找/usr/bin下的命令,如果这个命令不在这个目录下,当然会找不到命令,我们需要做的就是映射一个链接到/usr/bin目录下,相当于建立一个链接文件。
ln -s /usr/local/mysql/bin/mysql /usr/bin
6.2 设置远程登陆
登陆mysql(mysql -u root -p),使用mysql数据库(use mysql),并执行:update user set host = ‘%‘ where user = ‘root‘;最后执行flush privileges;
6.3建立mysql服务
cp -a ./support-files/mysql.server /etc/init.d/mysqld
chkconfig --add mysqld
chkconfig --list mysqld(检查服务是否生效)
6.4配置全局环境变量
vi /etc/profile
在 profile 文件底部添加如下两行配置
PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATH
原文地址:https://www.cnblogs.com/warmsmile/p/10210739.html