centos下安装mysql命令大全

官网5.7版本:https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-5.7.29-1.el7.x86_64.rpm-bundle.tar

可以使用xftp上传到Linux中

使用tar命令解压

tar -xvf mysql-5.7.29-1.el7.x86_64.rpm-bundle.tar —————————————————— 安装新版mysql前,需将系统自带的mariadb-lib卸载

rpm -qa|grep mariadb mariadb-libs-5.5.60-1.el7_5.x86_64

rpm -e --nodeps mariadb-libs-5.5.60-1.el7_5.x86_64

为了避免出现权限问题,给mysql解压文件所在目录赋予最大权限

chmod -R 777 mysql

严格按照顺序安装:mysql-community-common-5.7.29-1.el7.x86_64.rpm、mysql-community-libs-5.7.29-1.el7.x86_64.rpm、mysql-community-client-5.7.29-1.el7.x86_64.rpm、mysql-community-server-5.7.29-1.el7.x86_64.rpm这四个包

rpm -ivh mysql-community-common-5.7.29-1.el7.x86_64.rpm rpm -ivh mysql-community-libs-5.7.29-1.el7.x86_64.rpm rpm -ivh mysql-community-client-5.7.29-1.el7.x86_64.rpm rpm -ivh mysql-community-server-5.7.29-1.el7.x86_64.rpm

配置数据库

vim /etc/my.cnf

添加这三行

skip-grant-tables character_set_server=utf8 init_connect=SET NAMES utf8

skip-grant-tables:跳过登录验证 character_set_server=utf8:设置默认字符集UTF-8 init_connect=‘SET NAMES utf8’:设置默认字符集UTF-8

设置开机启动

systemctl start mysqld.service 启动mysql mysql

先设置一个简单的密码

update mysql.user set authentication_string=password(‘123456’) where user=‘root’;

立即生效

flush privileges;

退出mysql并停止mysql服务

systemctl stop mysqld.service

编辑my.cnf配置文件将:skip-grant-tables这一行注释掉 重启mysql服务

systemctl start mysqld.service 再次登录mysql

mysql -uroot -p123456

如果输入其他命令出错,再重设密码

set password=password(‘123456’);

开放端口 firewall-cmd --zone=public --add-port=3306/tcp --permanent –zone #作用域 –add-port=80/tcp #添加端口,格式为:端口/通讯协议 –permanent #永久生效,没有此参数重启后失效

重启防火墙 firewall-cmd --reload

开启远程登录 grant all privileges on . to ‘root’@’%’ identified by ‘123123’ with grant option;








Fedora26下Mysql改密码Unknown column ‘password’ in ‘field list’ 本意向修改一个用户的密码,网上搜到的命令为如下

1 mysql> update user set password=password(“新密码”) where user=”用户名”; 执行后报错  ERROR 1054(42S22) Unknown column ‘password’ in ‘field list’

错误的原因是 5.7版本下的mysql数据库下已经没有password这个字段了,password字段改成了authentication_string

所以请使用一下命令:

复制代码 复制代码

mysql -u root -p Enter password: ******** Welcome to the MySQL monitor. Commands end with ; or g. Your MySQL connection id is 12 Server version: 5.7.18-log MySQL Community Server (GPL)

Copyright © 2000, 2017, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners.

Type ‘help;’ or ‘h’ for help. Type ‘c’ to clear the current input statement.

mysql> use mysql; Database changed mysql> select User from user; #此处为查询用户命令 ±----------+ | User | ±----------+ | ******* | | mysql.sys | | root | ±----------+ 3 rows in set (0.00 sec)

mysql> update user set password=password(“") where user="”; #修改密码报错 ERROR 1054 (42S22): Unknown column ‘password’ in ‘field list’ mysql> update mysql.user set authentication_string=password(‘’) where user=’; #修改密码成功 Query OK, 1 row affected, 1 warning (0.00 sec) Rows matched: 1 Changed: 1 Warnings: 1

mysql> flush privileges; #立即生效 Query OK, 0 rows affected (0.00 sec)

mysql> quit Bye

n>mysql -u ******* -p #以该用户登录成功. Enter password: ******** ………………………… mysql>

经验分享 程序员 微信小程序 职场和发展