/etc/profile 中配置的环境变量在 sudo、root 用户下失效
/etc/profile 部分环境变量配置如下:
电脑上装了 mysql ,需要启动mysql 服务,普通用户启动失败错误权限不足,这就迫切需要 sudo mysqld 来启动 mysql 服务。
smqk@lenovo:~$ mysqld 2019-08-16 18:00:21 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details). 2019-08-16 18:00:21 0 [Note] --secure-file-priv is set to NULL. Operations related to importing and exporting data are disabled 2019-08-16 18:00:21 0 [Note] mysqld (mysqld 5.6.45) starting as process 7335 ... 2019-08-16 18:00:21 7335 [Warning] Can't create test file /usr/local/mysql-5.6.45-linux-glibc2.12-x86_64/data/lenovo.lower-test 2019-08-16 18:00:21 7335 [Warning] Can't create test file /usr/local/mysql-5.6.45-linux-glibc2.12-x86_64/data/lenovo.lower-test 2019-08-16 18:00:21 7335 [Note] Plugin 'FEDERATED' is disabled. mysqld: Can't find file: './mysql/plugin.frm' (errno: 13 - Permission denied) 2019-08-16 18:00:21 7335 [ERROR] Can't open the mysql.plugin table. Please run mysql_upgrade to create it. smqk@lenovo:~$ sudo mysqld sudo: mysqld:找不到命令 smqk@lenovo:~$
但是 su 切换到root用户也提示找不到命令。找不到命令就是环境变量未成功加载。修改 root 用户的 .bashrc 新增
source /etc/profile
重启命令终端解决问题。 当然想 root 偶尔生效也可以不增加配置,每次再需要环境变量生效时在命令行中执行 source /etc/profile 也可以。