Skip to content
Go back

Linux踩坑合集

Edit page

Linux 忘记 mysql root 密码,修改权限以及密码(mysql version < 5.7.9)

解决方案:

  1. 关掉数据库 service mysqld stop
  2. 执行 mysqld_safe --skip-grant-tables
  3. 打开数据库并进入 mysql 数据库中 mysql -u root mysql
  4. 查看所有用户的信息 SELECT user, host, password FROM user;
  5. 修改 root 用户密码 UPDATE user set password=password('newpassword') WHERE user='root';
  6. 刷新权限表并执行 FLUSH PRIVILEGES;
  7. exit

Linux 忘记 mysql root 密码,修改权限以及密码(mysql version 8.0)

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_root_password BY 'password';

连接数据库 1251 错误码

原因:
由于 mysql8 之前的版本中加密规则是 mysql_native_password, 而在 mysql 8.0 之后, 加密规则是 caching_sha2_password。
解决方案:

  1. 升级 Navicat 驱动
  2. 把 mysql 用户登录密码加密规则还原成 mysql_native_password.

我们进行方法二:

  1. 进入数据库
  2. 输入
ALTER USER 'root'@'localhost' IDENTIFIED BY 'password' PASSWORD EXPIRE NEVER; #修改加密规则
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password'; #更新一下用户的密码
FLUSH PRIVILEGES; #刷新权限

中文输入法

这里使用的是 googlepinyin 安装好相关的包之后,再设置-输入法-管理已安装语言中,安装中文,并修改输入法系统为:fcitx 随后重启。重启之后,右上角应该是有个白色的小按钮,点击之后配置输入法,注意有键盘(keyboard)字样的要放最上面,而且这个不代表输入法,是键盘布局的意思,是不会激活输入法的。

su root
apt-get install fcitx fcitx-googlepinyin fcitx-table-wbpy fcitx-pinyin fcitx-sunpinyin
yum groupinstall chinese support //安装中文环境支持

Ubuntu 修改分辨率

方案一(临时性)

cvt 1920 1080
sudo xrandr --newmode xxx # 填写上一条命令出现的modeline信息
sudo xrandr --addmode VGA-1 "1920x1080_60" # 添加显示模式
sudo xrandr --output  VGA-1 --mode "1920x1080_60.00" # 输出显示模式

方案二(永久性)

新版本的 Ubuntu 可能没有这个文件,所以这种方式可能失效。

sudo vim /etc/X11/xorg.conf

# 输入以下内容
"""
Section "Monitor"
Identifier "Configured Monitor"
Modeline "1920x1080_60.00"  173.00  1920 2048 2248 2576  1080 1083 1088 1120 -hsync +vsync
Option "PreferredMode" "1920x1080_60.00"
EndSection
Section "Screen"
Identifier "Default Screen"
Monitor "Configured Monitor"
Device "Configured Video Device"
EndSection
Section "Device"
Identifier "Configured Video Device"
EndSection
"""

另外的方式:

  1. 把临时替换分辨率的命令写进开机自启动脚本里面比如 ~/.bashrc 或者 /etc/profile 中;
  2. 把修改分辨率的命令写进 systemd 的启动脚本中;

systemd 学习:http://www.ruanyifeng.com/blog/2016/03/systemd-tutorial-commands.html

Debian7 apt-get 无法升级

Debian7 官方已经不提供源了,我们应该升级系统。

vi /etc/apt/sources.list

将所有的 wheezy 改成 jessie
执行升级:
apt-get upgrade apt-get update apt-get dist-upgrade

删除无用组件: apt-get autoremove

重启系统: reboot

删除无用内核: apt purge linux-image-3.2.0-4-amd64 -y

Ubuntu apt-get dist-upgrade 无法升级

错误信息:

E: Could not get lock /var/lib/dpkg/lock - open (11 Resource temporarily unavailable)
E: Unable to lock the administration directory (/var/lib/dpkg/) is another process using it?

问题分析: 有别的进程占用了 apt 命令,因为 apt 命令只能有一个进程使用,所以我们应该查看什么进程正在使用进程,判断是否需要 kill 掉;

解决方案:

  1. 清除 lock file 和 cache 的 lock file

    sudo rm /var/lib/apt/lists/lock
    sudo rm /var/cache/apt/archives/lock
    sudo rm /var/lib/dpkg/lock
  2. 列出使用中的进程并杀死

    ps -A | grep apt
    sudo kill -9 xxx

Ubuntu 换源

备份原始 sources.list

sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak

修改源文件 sources.list

sudo chmod 777 /etc/apt/sources.list # 编辑权限使得可编辑
sudo vim /etc/apt/sources.list # 打开编辑器
# 删除原来内容,更换为如下
# 清华源
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse

deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse

deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse

deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse

deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse

deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse

deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse

deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse

deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse

deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse

# 阿里源
deb http://mirrors.aliyun.com/ubuntu/ xenial main restricted universe multiverse

deb http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted universe multiverse

deb http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted universe multiverse

deb http://mirrors.aliyun.com/ubuntu/ xenial-proposed main restricted universe multiverse

deb http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse

deb-src http://mirrors.aliyun.com/ubuntu/ xenial main restricted universe multiverse

deb-src http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted universe multiverse

deb-src http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted universe multiverse

deb-src http://mirrors.aliyun.com/ubuntu/ xenial-proposed main restricted universe multiverse

deb-src http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse

上面的 bionic 是 18.04 的版本名,18.10 为 cosmic

版本号代号发布时间
20.04 LTSFocal Fossa2020/4/23
19.10Eoan Ermine2019/10/17
19.04Disco Dingo2019/4/19
18.10Cosmic Cuttlefish2018/10/18
18.04 LTSBionic Beaver2018/04/26
17.10Artful Aardvark2017/10/21
17.04Zesty Zapus2017/04/13
16.10Yakkety Yak2016/10/20
16.04 LTSXenial Xerus2016/04/21
15.10Wily Werewolf2015/10/23
15.04Vivid Vervet2015/04/22
14.10Utopic Unicorn2014/10/23
14.04 LTSTrusty Tahr2014/04/18
13.10Saucy Salamander2013/10/17
13.04Raring Ringtail2013/04/25
12.10Quantal Quetzal2012/10/18
12.04 LTSPrecise Pangolin2012/04/26
11.10Oneiric Ocelot2011/10/13
11.04(Unity 成为默认桌面环境)Natty Narwhal2011/04/28
10.10Maverick Meerkat2010/10/10
10.04 LTSLucid Lynx2010/04/29
9.10Karmic Koala2009/10/29
9.04Jaunty Jackalope2009/04/23
8.10Intrepid Ibex2008/10/30
8.04 LTSHardy Heron2008/04/24
7.10Gutsy Gibbon2007/10/18
7.04Feisty Fawn2007/04/19
6.10Edgy Eft2006/10/26
6.06 LTSDapper Drake2006/06/01
5.10Breezy Badger2005/10/13
5.04Hoary Hedgehog2005/04/08
4.10(初始发布版本)Warty Warthog2004/10/20

Ubuntu 18.10 安装 vim 失败

The following packages have unmet dependencies:
    vim : Depends: vim-common (= 2:8.0.1453-1ubuntu1.1)

可能是 Ubuntu 18.10 版本自带的 vim-common 不满足 vim 的版本要求,解决方案是卸载自带版本,然后直接安装 vim 使用 apt 自行管理依赖。

sudo apt purge vim-common
sudo apt intall vim

Ubuntu 依赖版本不一致问题

上面的版本不一致问题解决方案我觉得不太好,因为如果有两个软件使用的是不同版本的同一个依赖,但是这两个软件都要用,这就很麻烦。

网上检索到除了卸载新版,退版本以外的另一种解决方案(我不知道这个软件具体是是如何实现的,难道只是把退版本这件事自动化了?):

sudo apt install aptitude

sudo aptitude install xxx

curl 从 github 等网站下载文件出错

类似如下: curl: (7) Failed to connect to raw.githubusercontent.com port 443: Connection refused

如果打开网址也进不了页面的话,考虑网址被墙了,解决方案有几种:

  1. 修改 hosts ,最简单,但是不保证有效;
  2. 挂代理(没有相关网络知识会比较麻烦);
  3. 找国内来源(比如百度网盘有没有人共享这些文件等等);

修改 hosts

先备份原有的 hosts

sudo cp /etc/hosts /etc/hosts.bak

查看网址的 ip,我这里使用的是 http://ip.tool.chinaz.com/

picture 14

修改正使用的 hosts


## 原文件 ##

127.0.0.1   localhost
127.0.1.1   ubuntu

# The following lines are desirable for IPv6 capable hosts
::1     ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters

## 修改为 ##

127.0.0.1   localhost
127.0.1.1   ubuntu

# The following lines are desirable for IPv6 capable hosts
::1     ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters

151.101.108.133 raw.githubusercontent.com

保存文件完成。

Ubuntu 系统时间错误 时区正确

本来设置了清华的 apt 源,再执行 apt update 的时候,还是出现了 Release file for ... is not valid yet 的报错,发现是系统时间有问题,刚好是获取更新的 apt 源链接有问题。猜测是获取软件更新的时候需要校准系统时间和服务器的时间。

解决方案: 通过服务器校准时间 先安装 ntpdate

sudo apt install ntpdate

再获取服务器时间校准系统时间

sudo ntpdate ntp.ubuntu.com
sudo ntpdate time.nist.gov

Edit page
Share this post on:

Previous Post
Linux知识杂记
Next Post
Java 基础语法