有时在服务器上使用命令:mysql -uroot -p ; 尝试登录数据库。

系统提示 :

-bash: mysql: command not found

或者提示如下:

-bash: /usr/bin/mysql: No such file or directory

原因:这是由于系统默认会查找/usr/bin下的命令,如果这个命令不在这个目录下,当然会找不到命令,我们需要做的就是映射一个链接到/usr/bin目录下,相当于建立一个链接文件。

首先得知道mysql命令或mysqladmin命令的完整路径,比如mysql的路径是:/usr/local/mysql/bin/mysql,我们则可以这样执行命令:

# ln -s /usr/local/mysql/bin/mysql /usr/bin

如下图所示:

Linux - 任意位置登录MySQL(软链)与路径字段详解_软链
ln命令添加符号链接

使用ln命令添加符号链接如上述所示,那么查看某个符号链接详细信息呢,如下所示,使用命令​​ls -l​​:

[root@localhost conf]# ls -l /usr/bin/php
lrwxrwxrwx 1 root root 22 6月 25 20:46 /usr/bin/php -> /usr/local/php/bin/php

另外一种思路:

进入 /usr/local/mysql/bin 目录下(即,安装路径下),使用如下命令登录:

./mysql -uroot -p

【字段详解】:

1. ​​--basedir=/usr/local/mysql​

在 MySQL 的配置文件 my.ini 或者 my.cnf 文件中

basedir 参数

原文说明为:
Path to installation directory. All paths are usually resolved relative to this.

解释:

该参数指定了安装 MySQL 的安装路径,填写全路径可以解决相对路径所造成的问题。

2. ​​--datadir=/opt/mysql/data​

原文说明为:
Path to the database root

解释:
该参数指定了 MySQL 的数据库文件放在什么路径下。数据库文件即我们常说的 MySQL data 文件。

3. ​​--plugin-dir=/usr/local/mysql/lib/plugin​

The path name of the plugin directory.

If the plugin directory is writable by the server,
it may be possible for a user to write executable code to a file in the directory using SELECT ... INTO DUMPFILE.
This can be prevented by making plugin_dir read only to the server
or by setting --secure-file-priv to a directory where SELECT writes can be made safely.

4. ​​--user=mysql​

Run the mysqld server as the user having the name user_name or the numeric user ID user_id. 
(“User” in this context refers to a system login account, not a MySQL user listed in the grant tables.)
--系统登录账户
This option is mandatory when starting mysqld as root.
The server changes its user ID during its startup sequence,
causing it to run as that particular user rather than as root.

5. ​​--log-error=/opt/mysql/data/localhost.localdomain.err​

Log errors and startup messages to this file. 
See Section 6.4.2, “The Error Log”.
If the file name has no extension, the server adds an extension of .err.
If you omit the file name, the default log file on Unix and Unix-like systems is host_name.err in the data directory.
The default on Windows is host_name.err in the data directory, unless the --pid-file option is specified.
In that case, the default name is the PID file base name with a suffix of .err in the data directory.

6. ​​--open-files-limit=20480​

Changes the number of file descriptors available to mysqld. 
You should try increasing the value of this option if mysqld gives you the error Too many open files.
mysqld uses the option value to reserve descriptors with setrlimit().
Internally, the maximum value for this option is the maximum unsigned integer value, but the actual maximum is platform dependent.
If the requested number of file descriptors cannot be allocated, mysqld writes a warning to the error log.

mysqld may attempt to allocate more than the requested number of descriptors (if they are available),
using the values of max_connections and table_open_cache to estimate whether more descriptors will be needed.

On Unix, the value cannot be set less than ulimit -n.

7. ​​--pid-file=/opt/mysql/data/localhost.localdomain.pid​

The path name of the process ID file.
The server creates the file in the data directory unless an absolute path name is given to specify a different directory.
This file is used by other programs such as mysqld_safe to determine the server's process ID.

8. ​​--port=5902​

The number of the port on which the server listens for TCP/IP connections. 
This variable can be set with the --port option.

​更多信息点击查看​

https://dev.mysql.com/doc/refman/5.7/en/server-options.html#option_mysqld_pid-file