安装mysql及设置密码
二进制文件安装 ,官网给定具体安装步骤: https://dev.mysql.com/doc/refman/8.0/en/binary-installation.html
如果报错libnuma.so.1 ,需要手动添加
yum install libnuma*
apt-get install libnuma*
然后就是设置环境变量 export PATH = $PATH:/usr/local/mysql/bin
二进制安装查询mysql状态并启动关闭
service mysql.server status
service mysql.server start
service mysql.server stop
使用yum或者apt-get安装的需要启动mysql
查询mysql状态
service mysql status
关闭
service mysql stop
启动
service mysql start
在mysql操作命令行下
设置初始密码:
set password for root@localhost = password('123') ;
忘记密码:(5.7)
1.关闭mysql服务: service mysql.server stop
2.启动mysql时携带参数 --skip-grant-tables: mysqld_safe --skip-grant-tables &
3.启动mysql命令行: mysql
4.修改mysql密码: update mysql.user set authentication_string = password('123') where user = 'root';
注:5.7以后mysql的用户密码字段修改为authentication_string ,并且使用加密储存,所有设置密码需要加上函数password();
5.退出并重启mysql: service mysql.server restart
8.0版本重置密码:
由于8.0删除了password函数,所以使用其他方式修改
update mysql.user set authentication_string = '' where user = 'root';
alter user user() identified by '123';
navicat数据库工具连接mysql报错:不允许连接数据库时:
1.修改mysql的host为指定ip访问
select user,host from mysql.user;
update mysql.user set host = '%' where user = 'root'; //%通配符表示所有ip,默认localhost,也可以指定多个ip,用逗号分隔
2.如果还是不可以,可能是端口限制的原因,修改防火墙端口开放
iptables -I INPUT -p tcp --dport 8080 -j ACCEPT
注:如果在docker下操作这个命令,可能会报错,需要在创建容器的时候给予特权 docker run -itd --privileged