小技巧:将账号密码写入/etc/my.cnf

登录数据库在命令行使用账号密码非常不安全,如下也会出现警告信息

$ mysql -uroot -p123
mysql: [Warning] Using a password on the command line interface can be insecure.

这时我们把账号密码写入/etc/my.cnf配置文件中,使用mysql不加参数就能直接登录数据库,安全方便

#修改配置文件
$ cat /etc/my.cnf
...
[client] #注意账号密码需要写在此标签下
user=root 
password=123

#修改权限
# chown mysql.mysql /etc/my.cnf
# chmod 600 /etc/my.cnf

#重启数据库
$ /etc/init.d/mysqld restart

接下来就能使用mysql命令直接登录了

$ mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.

学习来自:《MySQL入门与提高实践》第五章 5.2节

posted @ 2021-03-31 08:05  努力吧阿团  阅读(1519)  评论(0编辑  收藏  举报