Linux_MySQL数据库安装
1、 准备安装包
2、卸载系统预安装的mysql
命令:查看rpm -qa|grep -i mysql
卸载:yum remove mysql
3、删除系统已有mysql用户、组,重新添加
cat /etc/passwd |grep mysql
userdel mysql
groupdel mysql (可能会报错)
重新添加并且指定组 useradd -g mysql mysql;给新建用户设置密码passwd mysql
4、上传软件包,解压更改属主、组
# cd /home/mysql/
# tar -zxvf mysql-5.7.21-linux-glibc2.12-x86_64.tar.gz
# mv mysql-5.7.21-linux-glibc2.12-x86_64 /usr/local/mysql
# chown -R mysql:mysql /usr/local/mysql
5、创建目录并授权
# cd /usr/local/mysql/
# mkdir data mysql-files
# chmod 750 mysql-files
# chown -R mysql .
# chgrp -R mysql .
6、初始化数据库
bin/mysqld --initialize --user=mysql
7、授予读写权限
# chown -R root .
# chown -R mysql data mysql-files
8、添加mysql启动脚本到系统服务
cp support-files/mysql.server /etc/init.d/mysql.server
9、启动数据库
service mysql.server start
10、登录
mysql -uroot –p
遇到的问题
1、Starting MySQL.2020-01-12T07:56:55.718637Z mysqld_safe error: log-error set to '/var/log/mariadb/mariadb.log', however file don't exists. Create writable for user 'mysql'.
ERROR! The server quit without updating PID file (/var/lib/mysql/localhost.localdomain.pid).
解决办法:在/var/lib/mysql下创建mariadb/ mariadb.log
授予MySQL的可执行权限chmod +x mysql
2、mysql -uroot -p
bash: mysql: command not found
解决办法:配置环境变量or建立软连接
#Mysql
MYSQL_HOME=/usr/local/mysql
PATH=$PATH:$MYSQL_HOME/bin
export PATH MYSQL_HOME
3、ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
解决办法:vim /etc/my.cnf
[client]
socket=/var/lib/mysql/mysql.sock 或 /tmp/ mysql.sock
[mysqld]
socket=/var/lib/mysql/mysql.sock 或 /tmp/ mysql.sock
4、ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
解决办法:在/etc/my.cnf中[mysqld]下加入skip-grant-tables(跳过密码输入)
5、进入MySQL修改密码
update user set password=password("hl135791") where user="root"
把vim /etc/my.cnf中的skip-grant-tables注释掉,重启MySQL服务service mysql.server restart再次进入mysql时需要重新更改密码
alter user 'root'@'localhost' identified by 'hl135791';