Linux安装mysql
( 操作前请确定当前使用root用户登录且切换到 / 根目录,root@VM-X-X-XXX / )例:
- 使用wget指令下载指定版本的mysql安装包(确保已安装wget)
wget https://downloads.mysql.com/archives/get/p/23/file/mysql-5.7.33-linux-glibc2.12-x86_64.tar.gz
- 解压
tar -zxvf mysql-5.7.33-linux-glibc2.12-x86_64.tar.gz -C /usr/local
- 改名
cd /usr/local
mv mysql-5.7.33-linux-glibc2.12-x86_64 mysql
- 创建用户和组
groupadd mysql
useradd -r -g mysql mysql
chown -R mysql.mysql /usr/local/mysql
- 创建data文件夹
cd /usr/local/mysql
mkdir data
- 安装依赖包
yum install libaio
7.初始化 (记得保存初始密码)
/usr/local/mysql/bin/mysqld --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data --initialize
- 配置
vim /etc/my.cnf
配置文件:
[mysqld]
datadir=/usr/local/mysql/data
basedir=/usr/local/mysql
socket=/tmp/mysql.sock
user=mysql
port=3306
character-set-server=utf8
# 取消密码验证
#skip-grant-tables
# # Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
- 将mysql加入到服务中
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
- 开机启动
chkconfig mysql on
- 启动mysql
service mysql start
- 登录mysql
/usr/local/mysql/bin/mysql -uroot -p
- 设置权限
# 进入mysql后
mysql> use mysql;
mysql> update user set host ='%'where user ='root' and host ='localhost';
mysql> flush privileges;
如报错:ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement. 则需要先使用 alter user 重置密码(设置后请忽略 14.修改密码)
mysql> alter user user() identified by '密码';
mysql> use mysql;
mysql> update user set host ='%'where user ='root' and host ='localhost';
mysql> flush privileges;
设置完成远程客户端就可以访问了
- 修改密码:
set password for root@localhost = password('123456');
15.navivat如果出现下面这种问题:
在mysql成功启动、网络能通、mysql已经授权成功的前提下, 直接登录到腾讯云-->找到控制台-->云服务器-->安全-->防火墙 -->添加规则 ; 加上3306这个端口就OK了。
- 创建用户
使用root远程登录,安全隐患非常大,建议创建一个admin用户进行后续操作,生产环境下请将root用户可登陆地址改为localhost或指定ip。