CentOS7位安装MySql教程
1.先检查系统是否装有mysql
rpm -qa | grep mysql
2.下载mysql的repo源
wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm
3.安装 mysql-community-release-el7-5.noarch.rpm包
sudo rpm -ivh mysql-community-release-el7-5.noarch.rpm
4.安装MySQL
sudo yum install mysql-server
5.重置MySQL密码
mysql -u root
如果报错:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
原因:原因是/var/lib/mysql的访问权限问题。
chown root /var/lib/mysql/
重启MySQL服务
service mysqld restart
接着登陆设置密码
mysql -u root
use mysql;
update user set password=password('123456') where user='root';
exit;
6.重启MySQL服务
service mysqld restart
接着设置Root账户远程连接密码,账户和密码都是 root
mysql -u root -p
GRANT ALL PRIVILEGES ON *.* TO root@"%" IDENTIFIED BY "root";
重启服务器
service mysqld restart
7.使用外网工具连接MySQL
连接mysql的用户名和密码都是 root
关闭防火墙
systemctl stop firewalld.service
下面为另一种办法,但是,测试没有成功
连接MySQL服务器,修改密码
1)查看初始密码
- [root@host50 ~]#grep –i 'password' /var/log/mysqld.log
- 2017-04-01T18:10:42.948679Z 1 [Note] A temporary password is generated for root@localhost: mtoa>Av<p6Yk //随机生成的管理密码为mtoa>Av<p6Yk
2)使用初始密码连接mysql服务
- [root@host50 ~]# mysql -u root -p'mtoa>Av<p6Yk' //初始密码登录,
- mysql: [Warning] Using a password on the command line interface can be insecure.
- Welcome to the MySQL monitor. Commands end with ; or \g.
- Your MySQL connection id is 11
- Server version: 5.7.17
- Copyright (c) 2000, 2016, 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> //登录成功后,进入SQL操作环境
3)重置数据库管理员roo本机登录密码
- mysql> show databases;
- ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement //提示必须修改密码
- mysql> alter user root@”localhost” identified by "123qqq…A"; //修改登陆密码
- Query OK, 0 rows affected (0.00 sec)
- mysql> exit //断开连接
- [root@host50 ~]#
4)修改密码策略
- [root@host50 ~]# mysql -uroot –p123qqq…A
- mysql>
- mysql>set global validate_password_policy=0; //只验证长度
- Query OK, 0 rows affected (0.00 sec)
- mysql>set global validate_password_length=6; //修改密码长度,默认值是8个字符
- Query OK, 0 rows affected (0.00 sec)
- mysql> alter user root@”localhost” identified by "tarena"; //修改登陆密码
- Query OK, 0 rows affected (0.00 sec)
- mysql>exit
5)使用修改后的密码登录
- [root@host50 ~]# mysql -uroot -ptarena //登录
- Welcome to the MySQL monitor. Commands end with ; or \g.
- Your MySQL connection id is 15
- Server version: 5.7.17 MySQL Community Server (GPL)
- Copyright (c) 2000, 2016, 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.
- mysql> show databases; //查看数据库
- +--------------------+
- | Database |
- +--------------------+
- | information_schema |
- | mysql |
- | performance_schema |
- | sys |
- +--------------------+
- 4 rows in set (0.00 sec)
- mysql>
- 张少龙博客
yum -y install httpd mariadb-server mariadb php php-mysql
[root@xuegod63 ~]# systemctl start mariadb
[root@xuegod63 ~]# mysql_secure_installation[root@xuegod63 ~]# vim /etc/php.ini #php运用程序的配置文件
改:211 short_open_tag = Off
为:211 short_open_tag = Onshow databases;
use mysql;
show tables;
select database();#查看所处的位置
mysql -e 'show databases' -uroot -p123456
select now(),user(),database();删库
MariaDB [xuegod]> drop database `HA-test`;
直接到数据库存放目录移出就行
MariaDB [HA]> create database `HA-test1`;
[root@xuegod63 mysql]# mv /var/lib/mysql/HA@002dtest1 /opt/
show databases; drop database if exists `HA-test`; #IF EXISTS:如果存在创建表:
MariaDB [xuegod]> create database xuegod;
MariaDB [xuegod]> use xuegod;
MariaDB [xuegod]> create table student(id int(20),name char(40),age int);查看表结构
MariaDB [xuegod]> desc student;
(4)查看创建表执行了哪些命令:
MariaDB [xuegod]> show create table student \G MariaDB [xuegod]> create table student2(id int(20),name char(40),age int)ENGINE=MyISAM DEFAULT CHARSET=utf8;
#可以指定表的默认存储引擎和字符集
alter table student rename students; #修改表名
alter table students modify id int(10);#修改字段类型
alter table students change name stname char(20);#修改名字和字段
alter table students add sex enum('M','W');#添加字段
alter table students add uid int(10) first;#添加到第一列
alter table students add address char(40) after age;#添加到age字段后面
alter table students drop address; #删除某address字段create table student(id int(20),name char(40),age int);
insert into student values(2,'lis',24),(3,'wange',26);
select * from student;
select * from student\G #字段按行显示
select *from HA.student;#跨库查询
delete from students where id=3;#删除数据
delete from students where age is null; 删除adge为空的内容
update students set sex='M' where id=2;更新
select distinct name,age from student;#去重查询
select id,name,age from student where id>3 and age>25;#多条件查询
select * from students where stname='zhangsan' and (age=21 or age=24);
select * from student where binary name='jk';#区分大小写查询 默认不区分 select distinct id from student order by id asc;#升序
select distinct id from student order by id desc;#降序 help show;mysqldump -uroot -p123456 -B 迁移的库名 > 导出名称.sql
yum 安装mysql5.7的方法:
yum -y remove mariadb*
rpm -Uvh https://repo.mysql.com//yum/mysql-5.7-community/el/7/x86_64/mysql57-community-release-el7-10.noarch.rpm
yum list #刷新yum源缓存
yum -y install mysql-community-server #安装mysql5.7
systemctl start mysqld #启动mysql会生成临时密码 grep "password" /var/log/mysqld.log 命令获取MySQL的临时密码 mysql -uroot -p'&B=o4Fp!Rq_X'方法一:首先,修改validate_password_policy参数的值
MariaDB [xuegod]> set global validate_password_policy=0; #定义复杂度
MariaDB [xuegod]> set global validate_password_length=1; #定义长度 默认是8
MariaDB [xuegod]> set password for 'root'@'localhost'=password('123456');
MariaDB [xuegod]> flush privileges;方法二:在/etc/my.cnf 可关闭密码强度审计插件,重启mysql服务
validate-password=ON/OFF/FORCE/FORCE_PLUS_PERMANENT#(及强制/永久强制使用)。
mysql -uroot -p123456 < 导出名称.sql
字符集的查询和修改
show variables like 'character_set%';#当前字符集
show create table user \G #查看表的字符集
SHOW CREATE DATABASE mysql;#查看库的字符集
SHOW FULL COLUMNS FROM user;#查看字段编码 ALTER DATABASE db_name DEFAULT CHARACTER SET character_name [COLLATE ...];
ALTER TABLE logtest DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
ALTER TABLE logtest CHANGE title title VARCHAR(100) CHARACTER SET utf8 COLLATE utf8_general_ci; select * from user\G数据库导入导出
mysqldump -uroot -p123456 -A >all.sql
mysqldump -uroot -p123456 --all-databases >all2.sql A:导入所有数据库
mysql -uroot -p123456 <all.sql强制修改密码5.7 mysql
5.7 版本强制修改密码
vi /etc/my.cnf
[mysqld]
skip-grant-tables 执行修改命令 5.7以前用update user
set
password=password(“新密码”) where user=”用户名”;
update user set authentication_string=password('123456') where User='root';无法建表sbtest1s删除表空间就可以了
[root@mysql115 ~]# ll /var/lib/mysql/pcms
总用量 36
-rw-r----- 1 mysql mysql 61 8月 17 09:02 db.opt
-rw-r----- 1 mysql mysql 65536 8月 17 09:09 sbtest1.ibd
[root@mysql115 ~]# rm /var/lib/mysql/pcms/sbtest1.ibd
rm:是否删除普通文件 "/var/lib/mysql/pcms/sbtest1.ibd"?y
CentOS7位安装MySql教程的更多相关文章
- CentOS7.5 安装MySql教程
CentOS7位安装MySql教程 1.先检查系统是否装有mysql rpm -qa | grep mysql 2.下载mysql的repo源 wget http://repo.mysql.com/m ...
- 阿里云Centos7上安装MySQL教程
1 基本安装过程 1.查看系统是否安装了mysql软件 # rpm -qa|grep -i mysql 2.将已经安装过的软件卸载掉.注意:这样的卸载是不彻底,不过这里够用了 # yum remove ...
- 【转】CentOS7 64位安装mysql教程
从最新版本的linux系统开始,默认的是 Mariadb而不是mysql!这里依旧以mysql为例进行展示 1.先检查系统是否装有mysql rpm -qa | grep mysql 这里返回空值,说 ...
- CentOS7 64位安装mysql教程
参考链接:http://baijiahao.baidu.com/s?id=1597184796823517712&wfr=spider&for=pc https://www.cnblo ...
- centos7 下安装mysql教程
最近要在centos服务器上配置环境,在部署mysql的时候,碰到各种各样的问题,网上博客文章也是有各种坑,目前发现一个比较好的博客: https://blog.csdn.net/xiaomojun/ ...
- CentOS7下安装MySQL并配置远程连接
一.CentOS7下安装MySQL数据库 CentOS7默认的安装包里面已经没有 MySQL-Server安装包了,远程镜像中也没有了. 默认的是MariaDB (MySQL的一个分支,开发这个分支的 ...
- CentOS7 中安装 MySQL
0. 说明 参考 centos7.2安装MySQL CentOS 7 下 Yum 安装 MySQL 5.7 两种方式安装 MySQL 安装 MySQL(yum) & 安装 MySQL(yum) ...
- CentOS7.4安装MySQL踩坑记录
CentOS7.4安装MySQL踩坑记录 time: 2018.3.19 CentOS7.4安装MySQL时网上的文档虽然多但是不靠谱的也多, 可能因为版本与时间的问题, 所以记录下自己踩坑的过程, ...
- centos7 yum 安装mysql
介绍在CentOS7上yum安装数据库服务器MySQL Community Server 5.7的方法. 准备 CentOS7默认安装了和MySQL有兼容性的MariaDB数据库,在我们安装MySQL ...
随机推荐
- android开源图表库MPAndroidChart(曲线图、直方图、饼状图)
github地址:https://github.com/PhilJay/MPAndroidChart 添加依赖: Add the following to your project level bui ...
- Ruby小白入门笔记之<Rubymine工具的快捷键>
智能快捷 Ctrl+Alt+G:弹出Generate Ctrl+Alt+L:格式化代码 Alt+F1:切换视图(Project, Structure, etc.). Alt+F2:弹出预览窗口,可选择 ...
- springboot2.0+mycat实验读写分离
声明:用户到达一定程度,架构就必须要考虑,因为在这个前提下,读写分离,尤为重要. 1.搭建mysql主从复制 https://www.cnblogs.com/ywjfx/p/10264383.html ...
- Selenium 2自动化测试实战6(异常)
一.异常 python用异常队形(exception object)来表示异常情况,遇到错误后,会引发异常.如果异常对象并未被处理和捕捉,则程序就会用所谓的回溯(Traceback,一种错误信息)来终 ...
- 阶段3 2.Spring_03.Spring的 IOC 和 DI_12 注入集合数据
再复制一份,改名3 常用的注入方式,这里选择set saveAccount方法输出所有的对象 map需要导包 配置xml 集合类型的值配置方式 在property标签里面再写标签 这里选择array. ...
- 慕课网_Java入门第三季
第1章 异常与异常处理 1-1 Java异常简介 (06:50) 1-2 Java中使用try..catch..finally实现异常处理 (05:08) import java.util.Input ...
- C++ lower_bound
代码 #include<iostream> #include<algorithm> using namespace std; int main(void) { ] = { 0. ...
- Hibernate 持久化对象和一级缓存
关于如何手动创建Hibernate,Hibernate初了解已经介绍了,接下来了解持久化对象和一级缓存. Hibernate的持久化类有三种状态: 1.Transient瞬时态:持久化对象没有唯一标识 ...
- 20个python项目--图片转字符画
转自实验楼:https://www.shiyanlou.com/courses/370/learning/?id=1191 代码: # -*- coding:utf-8 -*- from PIL im ...
- finreport 截图时间的函数