Ubuntu18.04 MySQL 5.7不再弹出root密码设置

于这个问题有两种解决方式,第一种是直接下载8.0版本的MySQL,不通过命令行的apt下载,第二种方法是本文研究的,针对已经通过apt安装的用户 安装MySQL 5.7 $ sudo apt-get install mysql-server mysql-client libmysqlclient-dev 安装完成之后会发现没有弹窗出来让用户设置密码,我们用下面的方式来解决 解决方法 先查看自动生成的用户名以及密码,可以看到这里的user=###和password=*** $ sudo cat /etc/mysql/debian.cnf 把看到的user和password记录下来,并且输入如下的命令 $ mysql -u### -p*** #这里的###和***由记录的值替换,就可以进入到mysql中 然后输入以下的命令来生成一个root用户 mysql> update mysql.user set authentication_string=PASSWORD("root") where User="root"; # 生成一个用户,但是会出现一个warning mysql> update mysql.user set plugin=”mysql_native_password”; # 解决警告 mysql> flush privileges; #更新所有权限 mysql> exit; #退出 最后重启一下MySQL即可 $ service mysql restart ...

July 11, 2018 · 1 min · 赖杰

Golang 实现 B-Tree与B+Tree

B-Tree与B+Tree基本概念 为什么在数据库中不使用时间复杂度为O(logN)的二叉查找树,是因为磁盘IO的问题,数据库索引是放在磁盘上的,数据量特别大时,索引也变得很大,不可能把所有的索引都放到内存当中,只能逐一加载每一个磁盘页。而在最坏情况下,磁盘IO次数对应着索引树的高度,所以为了减少磁盘IO次数,需要把树的高度减小。 B-Tree B-Tree性质 阶为M的B-树拥有以下的性质: 树的根或者是一片树叶,或者其孩子数在2和M之间 除根以外,所有的非叶节点的孩子数在 ⌈M/2⌉和M之间 所有的叶节点都在相同的深度上 每个节点存放至少M/2 - 1(上取整)和至多M - 1 个关键字(至少2个关键字) 非叶节点的关键字个数=孩子指针个数 - 1 节点内关键字有序 B-Tree实现 查看github B+Tree B+树与B树的差别在于: 非叶节点的孩子指针与关键字个数相同 所有关键字都在叶子节点的链表中出现(稠密索引),并且链表中的关键字是有序的 为所有叶子节点增加一个链指针 关键字都出现在叶子节点 不可能在非叶子节点命中 非叶子节点相当于叶子节点的索引(稀疏索引),叶子节点相当于是存储关键字的数据层 B+Tree实现 查看github...

July 11, 2018 · 1 min · 赖杰

记录一个Ubuntu16.10安装ElasticSearch的问题

其实这个问题没有真正解决,只是迫不得已的方法。 问题描述 首先是笔者的系统信息 $ uname -a Linux XPS 4.8.0-46-generic #49-Ubuntu SMP Fri Mar 31 13:57:14 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux 接下来下载apt自带的elasticsearch $ sudo apt install elasticsearch 下载非常的顺利,但是访问http://localhost:9200是拒绝访问的 接下来我们看看这时候elasticsearch的服务状态,大致是这样的 elasticsearch.service - LSB: Starts elasticsearch Loaded: loaded (/etc/init.d/elasticsearch; bad; vendor preset: enabled) Active: active (exited) since Thu 2017-04-21 12:03:54 EDT; 32min ago Docs: man:systemd-sysv-generator(8) Process: 1192 ExecStart=/etc/init.d/elasticsearch start (code=exited, status=0 Tasks: 0 (limit: 512) Apr 21 12:03:54 rubix2 systemd[1]: Starting LSB: Starts elasticsearch… Apr 21 12:03:54 rubix2 systemd[1]: Started LSB: Starts elasticsearch....

April 21, 2017 · 1 min · 赖杰

ssh:不能解析github.com的主机名

ssh: Could not resolve hostname ssh.github.com: Name or service not known fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists. 当笔者像平常一样使用着$git push origin master时,突然报错了,然后笔者又测试了一下 git clone 命令,仍然报错。然后记录一下解决方法 打开/etc/resolv.conf 添加两行nameserver nameserver 8.8.8.8 nameserver 8.8.4.4 ps: 这里如果直接修改/etc/resolv.conf重启之后会失效。解决方法 但是作者使用下的Ubuntu16.10使用上面的方法是有问题的,可能是因为我自己做了一些不知道什么的事 最终的解决方案是: 打开/etc/NetworkManager/NetworkManager.conf 注释(加上#)或删除dns=dnsmasq这一行 sudo service NetworkManager restart 完美解决...

March 19, 2017 · 1 min · 赖杰

Laravel 手动分页实现详解

因为Laravel 手册上对于手动分页的描述并不详细,这里大概说说笔者的实现方法 场景说明 在写一个大分类下所有文章的列表页时,笔者把取出来的数据都转换成了数组,这里为了清晰的说明并没有使用Repository来进行封装。 /** * 当parent_id为0时为顶级分类,这时候会把顶级分类 * 下的文章以及子分类下的文章都放到一个数组中 * 当parent_id不为0时取出对应分类下的文章 */ Cate::find($id)->first()->parent_id == 0 ? $listInfo = array_merge(Cate::with('articles')->where('id',$id)->get()->toArray(), Cate::with('articles')->where('parent_id',$id)->get()->toArray()) : $listInfo = Cate::with('articles')->where('id',$id)->get()->toArray(); 因为转换成数组的缘故,不能直接使用paginate()方法来实现分页。 手动实现分页 /** * ArticleListController.php * */ <?php namespace App\Http\Controllers; use App\Cate; use Illuminate\Pagination\LengthAwarePaginator; class ArtlistController extends AppController { public function index($id) { Cate::find($id)->first()->parent_id == 0 ? $listInfo = array_merge(Cate::with('articles')->where('id',$id)->get()->toArray(), Cate::with('articles')->where('parent_id',$id)->get()->toArray()) : $listInfo = Cate::with('articles')->where('id',$id)->get()->toArray(); $count = 0; foreach ($listInfo as $item) { $count += count($item['articles']); } $paginator = new LengthAwarePaginator($listInfo,$count,4); $categories = $this->parent(); return view('article....

March 14, 2017 · 1 min · 赖杰