centos中mysql 安装以及配置,建库
1.检测系统内部有没有安装其他的mysql数据库
rpm -qa | grep mysql
然后如果有的话删除这些mysql yum remove 查出来的所有名字
2.彻底删除系统中mysql的目录
find / -name mysql
将查出的所有目录删掉 rm -rf 查到的路径
3.下载mysql的rpm包
wget http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm
- 1
4.安装mysql源
yum localinstall mysql57-community-release-el7-8.noarch.rpm
- 1
5.重要一步
先尝试安装
yum install -y mysql-community-server
- 1
如果可以安装那么安装之后查询mysql版本 mysql -V
显示5.7版本则安装成功
如果安装成立5.6
那么修改mqsql源里面的一些 vi /etc/yum.repos.d/mysql-community.repo :比如要安装5.6版本,将5.7源的enabled=1改成enabled=0。然后再将5.6源的enabled=0改成enabled=1即可。
这里是将5.7的修改为1 5.6的修改为0
# Enable to use MySQL 5.5
[mysql55-community]
name=MySQL 5.5 Community Server
baseurl=http://repo.mysql.com/yum/mysql-5.5-community/el/7/$basearch/
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
# Enable to use MySQL 5.6
[mysql56-community]
name=MySQL 5.6 Community Server
baseurl=http://repo.mysql.com/yum/mysql-5.6-community/el/7/$basearch/
enabled=0 #####################################
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
[mysql57-community]
name=MySQL 5.7 Community Server
baseurl=http://repo.mysql.com/yum/mysql-5.7-community/el/7/$basearch/
enabled=1 #######################################
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
[mysql-tools-preview]
name=MySQL Tools Preview
baseurl=http://repo.mysql.com/yum/mysql-tools-preview/el/7/$basearch/
enabled=0
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
再次安装 yum install mysql-community-server
6.启动mysql服务
systemctl start mysqld
- 1
7.mysql开启启动
systemctl enable mysqld
- 1
8.查看mysql密码
grep 'temporary password' /var/log/mysqld.log
- 1
9.如果你什么都没有查到
那么默认密码是没有的
直接进入mysql
mysql -uroot -p
- 1
10.修改密码
***注意这里数据库为mysql5.7或以上password字段修改成了authentication_string;
set password = passowowd('你的密码');
- 1
如果你在这一步发生错误,那么请退出mysql后使用命令先更新一下数据库
mysql_upgrade -uroot -p
- 1
然后再次进入mysql设置root密码即可
如果还是不行的话,就使用下面方法
查看root密码
grep 'temporary password' /var/log/mysqld.log
- 1
查看后打开mysql并修改密码
mysql -uroot -p
首次修改密码会提示密码安全等级的错误,因此要先修改安全等级,再次修改才会生效
1、设置安全级别
set global validate_password_policy=0;
2、默认密码为8,可以设置为其他值,最小4位
set global validate_password_length=4;
3、设置root密码
set password for root@localhost = password('新密码');
- 1
- 2
- 3
- 4
- 5
- 6
11.开启mysql的root账户远程访问
- 进入mysql
mysql -uroot -p 输入密码登录
- 1
- 选择mysql数据库
use mysql;
- 1
- 修改root远程访问
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'password' WITH GRANT OPTION;
- 1
4.更新数据库
FLUSH PRIVILEGES;
- 1
注意这个时候防火墙要关闭,或者开放3306端口
二、导入数据库
1、首先建空数据库
mysql>create database abc;
2、导入数据库
方法一:
(1)选择数据库
mysql>use abc;
(2)设置数据库编码
mysql>set names utf8;
(3)导入数据(注意sql文件的路径)
mysql>source /home/abc/abc.sql;
方法二:
mysql -u用户名 -p密码 数据库名 < 数据库名.sql
mysql -uabc_f -p abc < abc.sql
如果安装成功报错
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this st
修改my.cnf配置 sed -i ‘/mysqld/a\skip-grant-tables’ /etc/my.cnf

重启mysql
systemctl restart mysqld
进入mysql
这次就不需要root密码了
use mysql;
UPDATE user SET Password = password('newpassword') where User = 'roo
刷新权限
flush privileges;
退出
quit
还原my.cnf配置sed -i 's/skip-grant-tables/#skip-grant-tables/g' /etc/my.cnf
- 9
再次重启mysql服务
systemctl restart mysqld
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 (c) 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>
centos中mysql 安装以及配置,建库的更多相关文章
- CentOS下mysql安装和配置
1.卸载原有mysql [root@iZ25ka6ra32Z /]# rpm -qa | grep mysql 查看该操作系统上是否已经安装了mysql数据库.有的话,我们就通过 rpm -e 命令 ...
- 【转】CentOS中vsftp安装、配置、卸载
1. 安装VSFTP yum -y install vsftpd 2. 配置vsftpd.conf文件 # Example config file /etc/vsftpd/vsftpd.conf # ...
- CentOS中vsftp安装、配置、卸载
1. 安装VSFTP 1 [root@localhost ~]# yum -y install vsftpd 2. 配置vsftpd.conf文件 [root@localhost ~]# vi /et ...
- 阿里云CentOS中vsftp安装、配置、卸载
1--卸载 查看当前服务器中的vsftpdrpm -qa|grep vsftpd 例如结果为:vsftpd-2.2.2-13.el6_6.1.x86_64执行卸载rpm -e vsftpd-2.2.2 ...
- centos中java安装跟配置
安装配置java环境 [root@JxateiLinux src]# Wget http://download.oracle.com/otn-pub/java/jdk/8u161-b12/2f38c ...
- CentOS中vsftp安装与配置
http://blog.chinaunix.net/uid-7271021-id-3086186.html 553 Could not create file 解决办法 [root@localhost ...
- centos 7.3 服务器环境搭建——MySQL 安装和配置
centos 7.3 服务器环境搭建——MySQL 安装和配置服务器信息如下:服务器:阿里云系统 centos 7.3 (阿里云该版本最新系统)mysql版本:5.7.18 (当前时间最新版本)连接服 ...
- centos 6.5安装并配置mysql
折腾了半天终于把mysql安装并配置好了,以下是安装步骤和遇到问题的解决方式 1.查看机器上是否已经安装了mysql或其相关项 # yum list installed | grep mysql如果安 ...
- 阿里云centos中mysql的安装及一些常识知识
------------------------------------------------------------------- 阿里云centos中mysql的安装 工具WinSCP v ...
随机推荐
- #error 、 #line 和 #pragma 的使用
1. #error 的用法 (1)#error 是一种预编译器指示字,用于生成一个编译错误消息 (2)用法:#error message //注意:message 不需要用双引号包围 (3)#erro ...
- HDU——T 1068 Girls and Boys
http://acm.hdu.edu.cn/showproblem.php?pid=1068 Time Limit: 20000/10000 MS (Java/Others) Memory Li ...
- ,典型递归问题-F(1025)mod 5 的值
watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/ ...
- iOS自动布局高级用法 && 纯代码约束写法
本文主要介绍几个我遇到的总结的高级用法(当然我相信肯定有不少比这还高级的). 简单的storyboard中上下左右约束,固定宽高啥的用法在这里就不做赘述了. autolayout自动布局是iOS6以后 ...
- Windows下Python2.7配置OpenCV2.4.10
所需文件: 1 Python2.7.13 链接: https://www.python.org/downloads/release/python-2713/ 这里选Windows 64位的安装包. 2 ...
- springBoot 打war包 程序包com.sun.istack.internal不存在的问题
使用的是 idea - Lifecycle-package 的方式打包(maven) 确认 <packaging>war</packaging> 修改启动类: (原启动类) ...
- Spring Boot AutoConfiguration注解@ConditionalXXXX之前生今世
1.注解@Conditional的定义 @Retention(RetentionPolicy.RUNTIME) @Target({ElementType.TYPE, ElementType.METHO ...
- AngularJs轻松入门源码托管至Github
Github是全球最大的代码托管平台,笔者玩Github有一段时间了,有很多开源项目的源码都托管在Github上,笔者在上面也发现了不少优秀的开源代码. 每次写完博文想在最后附上文章相关的代码,但是由 ...
- PostgreSQL Replication之第五章 设置同步复制(3)
5.3 冗余和停止复制 谈到同步复制,有一个现象一定不能被遗漏.想象一下,我们有一个同步复制的双节点集群.如果slave故障会发生什么?答案是master不能容易地区分慢slave和故障slave,因 ...
- links[v1]
justep core java Spring Boot ui5 template spring Cross-origin resource sharing 统一异常处理 数据库连接池的选择 Drui ...