MySQL是一种关系型数据库管理系统,关系数据库将数据保存在不同的表中,而不是将所有数据放在一个大仓库内,这样就增加了速度并提高了灵活性。
tar.gz包安装
#如没有安装wget则无法使用,以装,则直接省略该步~!
yum -y install wget
直接从官方下载#~耐心等待即可~-~-~
wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz
解压
tar xzvf mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz
ls
mv mysql-5.7.24-linux-glibc2.12-x86_64 /usr/local/mysql #移动该文件到/usr/local/下,并将文件夹名称修改为mysql
mkdir /usr/local/mysql/data #在/usr/local/mysql目录下创建data目录
cd
创建mysql用户组和用户
cat /etc/group | grep mysql
cat /etc/passwd |grep mysql
groupadd mysql
useradd -r -g mysql mysql
更改mysql目录下所有的目录及文件夹所属的用户组和用户,以及权限
chown -R mysql:mysql /usr/local/mysqlchmod -R 755 /usr/local/mysql
检查该链接库文件有没有安装使用
rpm -qa|grep libaio
yum install libaio-devel.x86_64
yum -y install numactl
编译安装并初始化mysql,务必记住初始化输出日志末尾的密码~~红框为数据库管理员登入临时密码!!!
cd /usr/local/mysql/bin
./mysqld --initialize --user=mysql --datadir=/usr/local/mysql/data --basedir=/usr/local/mysql
vi /etc/my.cnf[mysqld]
datadir=/usr/local/mysql/data
port=3306
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
symbolic-links=0
max_connections=600
innodb_file_per_table=1
lower_case_table_names=1
character_set_server=utf8
/usr/local/mysql/support-files/mysql.server start
ps -ef|grep mysql | grep -v grep
ps -ef|grep mysqld | grep -v grep
添加软连接,并重启mysql服务
ln -s /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqlln -s /usr/local/mysql/bin/mysql /usr/bin/mysqlservice mysql restart
输入临时密码
mysql -u root -p
#修改密码
set password for root@localhost = password('自定义');
#开放远程连接
use mysql;
update user set user.Host='%' where user.User='root';
flush privileges;
quit
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld #将服务文件拷贝到init.d下,并重命名为mysqlchmod +x /etc/init.d/mysqld #赋予可执行权限chkconfig --add mysqld #添加服务chkconfig --list ##显示服务列表
yum安装mysql
下载并安装MySQL官方的 Yum Repository
wget http://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm
安装MySQL
rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022
yum -y install mysql mysql-server mysql-devel
systemctl start mysqld.service
systemctl status mysqld.service
查看日志文件中找出随机密码
grep "password" /var/log/mysqld.log
修改密码
ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';
开发远程访问
grant all privileges on *.* to 'root'@'%' identified by ' 123456' with grant option;
flush privileges;
exit;
vi /etc/my.cnf,添加下面的内容,支持弱口令密码
character_set_server=utf8
init_connect='SET NAMES utf8'
#添加validate_password_policy配置
validate_password_policy=0
#关闭密码策略
validate_password = off
显示字符编码
show variables like '%character%';
显示密码策略
show variables like '%password%';
连接mysql可能会遇到的问题
Navicat Premium 12远程报错及处理方法
报错- lost connection to mysql server at 'reading initial communication packet',system error:0
vim /etc/my.cnf 中的[mysqld]下添加skip-name-resolve
#报错1698 Access denied for user *@*
mysql -u root -p
#进行远程连接授权
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION;
GRANT ALL PRIVILEGES ON *.* TO 'zabbix'@'%' WITH GRANT OPTION;
flush privileges;
use zabbix;
GRANT ALL PRIVILEGES ON *.* TO 'zabbix'@'%'IDENTIFIED BY '111111' WITH GRANT OPTION;
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%'IDENTIFIED BY '111111' WITH GRANT OPTION;
flush privileges;
记华为云服务器配置mysql-Navicat连接
新增一个安全组设置
Navicat连接