月份:2019年11月

cannot load such file — active_support/core_ext/object/blank 报错处理(brew update原因)

手贱跑了下brew update,结果一直没成功,然后打开终端报这个错。

Traceback (most recent call last):
    3: from /usr/local/Homebrew/Library/Homebrew/brew.rb:23:in `<main>'
    2: from /usr/local/Homebrew/Library/Homebrew/brew.rb:23:in `require_relative'
    1: from /usr/local/Homebrew/Library/Homebrew/global.rb:12:in `<top (required)>'
/usr/local/Homebrew/Library/Homebrew/global.rb:12:in `require': cannot load such file -- active_support/core_ext/object/blank (LoadError)

网上学习后,发现解决方法也很简单:
执行命令:brew update-reset,重新设置下brew的配置。

记录学习~

Authentication plugin ‘caching_sha2_password’ cannot be loaded: 客户端工具连接MySQL报错处理方式

最近在用Navicat连接新安装的MySQL<8.0.17>数据库时会出现Authentication plugin 'caching_sha2_password' cannot be loaded的错误。

出现这个原因是mysql8 之前的版本中加密规则是mysql_native_password,而在mysql8之后,加密规则是caching_sha2_password, 解决问题方法有两种,一种是升级navicat驱动,一种是把mysql用户登录密码加密规则还原成mysql_native_password.

具体代码及操作如下:

# 连接mysql
zhujin@zhujindeMacBook-Pro ~ % mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 11
Server version: 8.0.17 MySQL Community Server - GPL
Copyright (c) 2000, 2019, 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> ALTER USER 'root'@'localhost' IDENTIFIED BY 'password' PASSWORD EXPIRE NEVER; 
Query OK, 0 rows affected (0.01 sec)
# 设置新的加密规则下的密码
mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'zj123456';
Query OK, 0 rows affected (0.01 sec)
# 刷新规则
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)

然后就顺利连上了。

MacOS zsh: command not found: mysql 解决方案

最近重新安装了Mac上的MySQL,突然发现从终端连接不上,command not found: mysql。

zhujin@zhujindeMacBook-Pro ~ % mysql
zsh: command not found: mysql

很明显我们一眼就知道,这属于mysql命令没有链接上而已,很好处理。
直接通过alias设置别名就行了, 常见的设置别名的文件如下。

~/.bashrc:该文件包含专用于你的bash shell的bash信息,当登录时以及每次打开新的shell时,该文件被读取.(每个用户都有一个.bashrc文件,在用户目录下)

~/.bash_profile:每个用户都可使用该文件输入专用于自己使用的shell信息,当用户登录时,该文件仅仅执行一次!默认情况下,他设置一些环境变量,执行用户的.bashrc文件.

~/.zshrc:zsh配置文件,每次打开新的shell时,该文件被读取.如果没有,可以自行创建。

所以,我们可以在~/.bashrc 或者 ~/.zshrc中写下别名,首先看看mysql安装地址。

我没有修改过,所以默认 /usr/local/mysql,所以,在~/.bashrc 或者 ~/.zshrc任一文件中添加:

alias mysql=/usr/local/mysql/bin/mysql

然后source一下,试试效果:

# 编辑.zshrc添加alias语句
zhujin@zhujindeMacBook-Pro ~ % vim .zshrc
# 运行一次.zshrc文件
zhujin@zhujindeMacBook-Pro ~ % source .zshrc 
# 尝试连接mysql
zhujin@zhujindeMacBook-Pro ~ % mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.17 MySQL Community Server - GPL

Copyright (c) 2000, 2019, 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> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.01 sec)

ubuntu 新建用户并设置sudo权限

首先使用adduser添加用户

root@iZbp121mi6a5espq574bonZ:~# adduser test
Adding user `test' ...
Adding new group `test' (1001) ...
Adding new user `test' (1001) with group `test' ...
Creating home directory `/home/test' ...
Copying files from `/etc/skel' ...
# 登录密码
Enter new UNIX password: 
# 再次输入密码
Retype new UNIX password: 
passwd: password updated successfully
Changing the user information for test
Enter the new value, or press ENTER for the default
# 一些有的没的各种信息,我一般是不写的
        Full Name []: 
        Room Number []: 
        Work Phone []: 
        Home Phone []: 
        Other []: 
Is the information correct? [Y/n] 

这样就相当于已经建立完成了,id <用户名>看一下

root@iZbp121mi6a5espq574bonZ:~# id test
uid=1001(test) gid=1001(test) groups=1001(test)

可以看到,用户已经创建成功了,接下来把他放到sudo组

root@iZbp121mi6a5espq574bonZ:~# adduser test sudo
Adding user `test' to group `sudo' ...
Adding user test to group sudo
Done.

接下来看一下id <用户名>,会发现多了个sudo组,那么这个用户就已经有sudo权限了

root@iZbp121mi6a5espq574bonZ:~# id test
uid=1001(test) gid=1001(test) groups=1001(test),27(sudo)

大功告成,谢谢惠顾。

macOS Catalina 下干净彻底地卸载 MySQL并重装MySQL

最近系统升级了macOS Catalina,发现好多软件都不能用了,最主要mysql也不能用了,因为网上找了半天没怎么找到特别方便的处理方案,之前的版本也比较低,所以准备卸载了,然后重新安装。

------ 卸载 ------

卸载的话比较粗糙,直接删除了所有相关的文件与文件夹。

sudo rm /usr/local/mysql
sudo rm -rf /usr/local/mysql*
sudo rm -rf /Library/StartupItems/MySQLCOM
sudo rm -rf /Library/PreferencePanes/My*
sudo rm -rf /Library/PreferencePanes/My*
sudo rm -rf /Library/Receipts/mysql*
sudo rm -rf /Library/Receipts/MySQL*
sudo rm -rf /var/db/receipts/com.mysql.*

------安装------
从官方网站下下载最新的mysql(需要科学上网):
https://downloads.mysql.com/archives/community/
8.0.17的下载地址是,如果没有翻墙工具,可以尝试直接用迅雷下:
https://cdn.mysql.com/archives/mysql-8.0/mysql-8.0.17-macos10.14-x86_64.dmg
下载完成后,双击无脑安装。

Linux, mac, Ubuntu 删除文件夹和文件的命令

rm 代表删除
-r 就是向下递归,不管有多少级目录,一并删除
-f 就是直接强行删除,不作任何提示的意思

// 示例
rm *
删除当前文件夹内所有文件

rm -rf *
删除当前文件夹内所有文件及文件夹及所有文件

rm <文件名>
删除某指定文件名

rm -rf <文件夹>
删除指定的文件夹及其下的所有文件与文件夹