0

I tried to set password for root with mysqladmin like this:

sunqingyao@sunqingyao-MacBookAir:~$ sudo mysqld_safe --user=mysql &
[1] 8538
sunqingyao@sunqingyao-MacBookAir:~$ mysqladmin -u root password
New password: 
Confirm new password: 
Warning: Since password will be sent to server in plain text, use ssl connection to ensure password safety.

However, I can still log in as root without a password:

sunqingyao@sunqingyao-MacBookAir:~$ mysql -u root
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 17
Server version: 5.7.18 MySQL Community Server (GPL)

Copyright (c) 2000, 2017, 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> SELECT User, Host, HEX(authentication_string) FROM mysql.user;
+-----------+-----------+------------------------------------------------------------------------------------+
| User      | Host      | HEX(authentication_string)                                                         |
+-----------+-----------+------------------------------------------------------------------------------------+
| root      | localhost | 2A36333834303341353032304237313045463146464537413041463546443635453244324430453637 |
| mysql.sys | localhost | 2A5448495349534E4F544156414C494450415353574F52445448415443414E42455553454448455245 |
+-----------+-----------+------------------------------------------------------------------------------------+
2 rows in set (0.00 sec)

mysql> 

As you can see, I don't have to use mysql -u root -p to select something from a database.

However, if I run mysql -u root -p and enter a wrong password, I won't be able to log in.

sunqingyao@sunqingyao-MacBookAir:~$ mysql -u root -p
Enter password: 
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

Here is the output of strace mysql -u root:

sunqingyao@sunqingyao-MacBookAir:~$ sudo mysqld_safe --user=mysql &
[1] 4404
sunqingyao@sunqingyao-MacBookAir:~$ strace mysql -u root
execve("/usr/local/mysql/bin/mysql", ["mysql", "-u", "root"], [/* 72 vars */]) = 0
brk(NULL)                               = 0x1cf2000
access("/etc/ld.so.nohwcap", F_OK)      = -1 ENOENT (No such file or directory)
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f65649fa000
access("/etc/ld.so.preload", R_OK)      = -1 ENOENT (No such file or directory)
open("/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=113913, ...}) = 0
mmap(NULL, 113913, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7f65649de000
close(3)                                = 0
access("/etc/ld.so.nohwcap", F_OK)      = -1 ENOENT (No such file or directory)
open("/lib/x86_64-linux-gnu/libpthread.so.0", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\260`\0\0\0\0\0\0"..., 832) = 832
fstat(3, {st_mode=S_IFREG|0755, st_size=138696, ...}) = 0
mmap(NULL, 2212904, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f65645ba000
mprotect(0x7f65645d2000, 2093056, PROT_NONE) = 0
mmap(0x7f65647d1000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x17000) = 0x7f65647d1000
mmap(0x7f65647d3000, 13352, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7f65647d3000
close(3)                                = 0
access("/etc/ld.so.nohwcap", F_OK)      = -1 ENOENT (No such file or directory)
open("/lib/x86_64-linux-gnu/librt.so.1", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\0!\0\0\0\0\0\0"..., 832) = 832
fstat(3, {st_mode=S_IFREG|0644, st_size=31712, ...}) = 0
mmap(NULL, 2128832, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f65643b2000
mprotect(0x7f65643b9000, 2093056, PROT_NONE) = 0
mmap(0x7f65645b8000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x6000) = 0x7f65645b8000
close(3)                                = 0
access("/etc/ld.so.nohwcap", F_OK)      = -1 ENOENT (No such file or directory)
open("/lib/x86_64-linux-gnu/libdl.so.2", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\240\r\0\0\0\0\0\0"..., 832) = 832
fstat(3, {st_mode=S_IFREG|0644, st_size=14608, ...}) = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f65649dd000
mmap(NULL, 2109680, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f65641ae000
mprotect(0x7f65641b1000, 2093056, PROT_NONE) = 0
mmap(0x7f65643b0000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x2000) = 0x7f65643b0000
close(3)                                = 0
access("/etc/ld.so.nohwcap", F_OK)      = -1 ENOENT (No such file or directory)
open("/lib/x86_64-linux-gnu/libncurses.so.5", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0`^\0\0\0\0\0\0"..., 832) = 832
fstat(3, {st_mode=S_IFREG|0644, st_size=138112, ...}) = 0
mmap(NULL, 2233544, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f6563f8c000
mprotect(0x7f6563fad000, 2093056, PROT_NONE) = 0
mmap(0x7f65641ac000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x20000) = 0x7f65641ac000
close(3)                                = 0
access("/etc/ld.so.nohwcap", F_OK)      = -1 ENOENT (No such file or directory)
open("/usr/lib/x86_64-linux-gnu/libstdc++.so.6", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\3\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0 \235\10\0\0\0\0\0"..., 832) = 832
fstat(3, {st_mode=S_IFREG|0644, st_size=1566440, ...}) = 0
mmap(NULL, 3675136, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f6563c0a000
mprotect(0x7f6563d7c000, 2097152, PROT_NONE) = 0
mmap(0x7f6563f7c000, 49152, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x172000) = 0x7f6563f7c000
mmap(0x7f6563f88000, 13312, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7f6563f88000
close(3)                                = 0
access("/etc/ld.so.nohwcap", F_OK)      = -1 ENOENT (No such file or directory)
open("/lib/x86_64-linux-gnu/libm.so.6", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\3\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\0V\0\0\0\0\0\0"..., 832) = 832
fstat(3, {st_mode=S_IFREG|0644, st_size=1088952, ...}) = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f65649dc000
mmap(NULL, 3178744, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f6563901000
mprotect(0x7f6563a09000, 2093056, PROT_NONE) = 0
mmap(0x7f6563c08000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x107000) = 0x7f6563c08000
close(3)                                = 0
access("/etc/ld.so.nohwcap", F_OK)      = -1 ENOENT (No such file or directory)
open("/lib/x86_64-linux-gnu/libgcc_s.so.1", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0p*\0\0\0\0\0\0"..., 832) = 832
fstat(3, {st_mode=S_IFREG|0644, st_size=89696, ...}) = 0
mmap(NULL, 2185488, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f65636eb000
mprotect(0x7f6563701000, 2093056, PROT_NONE) = 0
mmap(0x7f6563900000, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x15000) = 0x7f6563900000
close(3)                                = 0
access("/etc/ld.so.nohwcap", F_OK)      = -1 ENOENT (No such file or directory)
open("/lib/x86_64-linux-gnu/libc.so.6", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\3\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0P\t\2\0\0\0\0\0"..., 832) = 832
fstat(3, {st_mode=S_IFREG|0755, st_size=1868984, ...}) = 0
mmap(NULL, 3971488, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f6563321000
mprotect(0x7f65634e1000, 2097152, PROT_NONE) = 0
mmap(0x7f65636e1000, 24576, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x1c0000) = 0x7f65636e1000
mmap(0x7f65636e7000, 14752, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7f65636e7000
close(3)                                = 0
access("/etc/ld.so.nohwcap", F_OK)      = -1 ENOENT (No such file or directory)
open("/lib/x86_64-linux-gnu/libtinfo.so.5", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0p\310\0\0\0\0\0\0"..., 832) = 832
fstat(3, {st_mode=S_IFREG|0644, st_size=167240, ...}) = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f65649db000
mmap(NULL, 2264256, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f65630f8000
mprotect(0x7f656311d000, 2093056, PROT_NONE) = 0
mmap(0x7f656331c000, 20480, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x24000) = 0x7f656331c000
close(3)                                = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f65649da000
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f65649d9000
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f65649d7000
arch_prctl(ARCH_SET_FS, 0x7f65649d7740) = 0
mprotect(0x7f65636e1000, 16384, PROT_READ) = 0
mprotect(0x7f656331c000, 16384, PROT_READ) = 0
mprotect(0x7f6563c08000, 4096, PROT_READ) = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f65649d6000
mprotect(0x7f6563f7c000, 40960, PROT_READ) = 0
mprotect(0x7f65643b0000, 4096, PROT_READ) = 0
mprotect(0x7f65641ac000, 4096, PROT_READ) = 0
mprotect(0x7f65647d1000, 4096, PROT_READ) = 0
mprotect(0x7f65645b8000, 4096, PROT_READ) = 0
mprotect(0x7f65649fc000, 4096, PROT_READ) = 0
munmap(0x7f65649de000, 113913)          = 0
set_tid_address(0x7f65649d7a10)         = 4411
set_robust_list(0x7f65649d7a20, 24)     = 0
rt_sigaction(SIGRTMIN, {0x7f65645bfb50, [], SA_RESTORER|SA_SIGINFO, 0x7f65645cb390}, NULL, 8) = 0
rt_sigaction(SIGRT_1, {0x7f65645bfbe0, [], SA_RESTORER|SA_RESTART|SA_SIGINFO, 0x7f65645cb390}, NULL, 8) = 0
rt_sigprocmask(SIG_UNBLOCK, [RTMIN RT_1], NULL, 8) = 0
getrlimit(RLIMIT_STACK, {rlim_cur=8192*1024, rlim_max=RLIM64_INFINITY}) = 0
brk(NULL)                               = 0x1cf2000
brk(0x1d24000)                          = 0x1d24000
ioctl(0, TCGETS, {B38400 opost isig icanon echo ...}) = 0
ioctl(1, TCGETS, {B38400 opost isig icanon echo ...}) = 0
dup(1)                                  = 3
close(3)                                = 0
stat("/etc/my.cnf", 0x7ffc05533210)     = -1 ENOENT (No such file or directory)
stat("/etc/mysql/my.cnf", {st_mode=S_IFREG|0644, st_size=1190, ...}) = 0
open("/etc/mysql/my.cnf", O_RDONLY)     = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=1190, ...}) = 0
read(3, "# Copyright (c) 2015, 2016, Orac"..., 4096) = 1190
open("/etc/mysql/conf.d/", O_RDONLY|O_NONBLOCK|O_DIRECTORY|O_CLOEXEC) = 4
fstat(4, {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
getdents(4, /* 4 entries */, 32768)     = 120
getdents(4, /* 0 entries */, 32768)     = 0
close(4)                                = 0
stat("/etc/mysql/conf.d/mysql.cnf", {st_mode=S_IFREG|0644, st_size=875, ...}) = 0
open("/etc/mysql/conf.d/mysql.cnf", O_RDONLY) = 4
fstat(4, {st_mode=S_IFREG|0644, st_size=875, ...}) = 0
read(4, "# Copyright (c) 2015, 2016, Orac"..., 4096) = 875
read(4, "", 4096)                       = 0
close(4)                                = 0
stat("/etc/mysql/conf.d/mysqldump.cnf", {st_mode=S_IFREG|0644, st_size=55, ...}) = 0
open("/etc/mysql/conf.d/mysqldump.cnf", O_RDONLY) = 4
fstat(4, {st_mode=S_IFREG|0644, st_size=55, ...}) = 0
read(4, "[mysqldump]\nquick\nquote-names\nma"..., 4096) = 55
read(4, "", 4096)                       = 0
close(4)                                = 0
read(3, "", 4096)                       = 0
close(3)                                = 0
stat("/usr/local/mysql/etc/my.cnf", 0x7ffc05533210) = -1 ENOENT (No such file or directory)
stat("/home/sunqingyao/.my.cnf", 0x7ffc05533210) = -1 ENOENT (No such file or directory)
stat("/home/sunqingyao/.mylogin.cnf", 0x7ffc05533210) = -1 ENOENT (No such file or directory)
socket(PF_LOCAL, SOCK_STREAM|SOCK_CLOEXEC|SOCK_NONBLOCK, 0) = 3
connect(3, {sa_family=AF_LOCAL, sun_path="/var/run/nscd/socket"}, 110) = -1 ENOENT (No such file or directory)
close(3)                                = 0
socket(PF_LOCAL, SOCK_STREAM|SOCK_CLOEXEC|SOCK_NONBLOCK, 0) = 3
connect(3, {sa_family=AF_LOCAL, sun_path="/var/run/nscd/socket"}, 110) = -1 ENOENT (No such file or directory)
close(3)                                = 0
open("/etc/nsswitch.conf", O_RDONLY|O_CLOEXEC) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=529, ...}) = 0
read(3, "# /etc/nsswitch.conf\n#\n# Example"..., 4096) = 529
read(3, "", 4096)                       = 0
close(3)                                = 0
open("/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=113913, ...}) = 0
mmap(NULL, 113913, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7f65649de000
close(3)                                = 0
access("/etc/ld.so.nohwcap", F_OK)      = -1 ENOENT (No such file or directory)
open("/lib/x86_64-linux-gnu/tls/x86_64/libnss_db.so.2", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat("/lib/x86_64-linux-gnu/tls/x86_64", 0x7ffc05537460) = -1 ENOENT (No such file or directory)
open("/lib/x86_64-linux-gnu/tls/libnss_db.so.2", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat("/lib/x86_64-linux-gnu/tls", 0x7ffc05537460) = -1 ENOENT (No such file or directory)
open("/lib/x86_64-linux-gnu/x86_64/libnss_db.so.2", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat("/lib/x86_64-linux-gnu/x86_64", 0x7ffc05537460) = -1 ENOENT (No such file or directory)
open("/lib/x86_64-linux-gnu/libnss_db.so.2", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat("/lib/x86_64-linux-gnu", {st_mode=S_IFDIR|0755, st_size=16384, ...}) = 0
open("/usr/lib/x86_64-linux-gnu/tls/x86_64/libnss_db.so.2", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat("/usr/lib/x86_64-linux-gnu/tls/x86_64", 0x7ffc05537460) = -1 ENOENT (No such file or directory)
open("/usr/lib/x86_64-linux-gnu/tls/libnss_db.so.2", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat("/usr/lib/x86_64-linux-gnu/tls", 0x7ffc05537460) = -1 ENOENT (No such file or directory)
open("/usr/lib/x86_64-linux-gnu/x86_64/libnss_db.so.2", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat("/usr/lib/x86_64-linux-gnu/x86_64", 0x7ffc05537460) = -1 ENOENT (No such file or directory)
open("/usr/lib/x86_64-linux-gnu/libnss_db.so.2", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat("/usr/lib/x86_64-linux-gnu", {st_mode=S_IFDIR|0755, st_size=69632, ...}) = 0
open("/lib/tls/x86_64/libnss_db.so.2", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat("/lib/tls/x86_64", 0x7ffc05537460) = -1 ENOENT (No such file or directory)
open("/lib/tls/libnss_db.so.2", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat("/lib/tls", 0x7ffc05537460)        = -1 ENOENT (No such file or directory)
open("/lib/x86_64/libnss_db.so.2", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat("/lib/x86_64", 0x7ffc05537460)     = -1 ENOENT (No such file or directory)
open("/lib/libnss_db.so.2", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat("/lib", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
open("/usr/lib/tls/x86_64/libnss_db.so.2", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat("/usr/lib/tls/x86_64", 0x7ffc05537460) = -1 ENOENT (No such file or directory)
open("/usr/lib/tls/libnss_db.so.2", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat("/usr/lib/tls", 0x7ffc05537460)    = -1 ENOENT (No such file or directory)
open("/usr/lib/x86_64/libnss_db.so.2", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat("/usr/lib/x86_64", 0x7ffc05537460) = -1 ENOENT (No such file or directory)
open("/usr/lib/libnss_db.so.2", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat("/usr/lib", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
munmap(0x7f65649de000, 113913)          = 0
open("/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=113913, ...}) = 0
mmap(NULL, 113913, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7f65649de000
close(3)                                = 0
access("/etc/ld.so.nohwcap", F_OK)      = -1 ENOENT (No such file or directory)
open("/lib/x86_64-linux-gnu/libnss_files.so.2", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\260!\0\0\0\0\0\0"..., 832) = 832
fstat(3, {st_mode=S_IFREG|0644, st_size=47600, ...}) = 0
mmap(NULL, 2168600, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f6562ee6000
mprotect(0x7f6562ef1000, 2093056, PROT_NONE) = 0
mmap(0x7f65630f0000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0xa000) = 0x7f65630f0000
mmap(0x7f65630f2000, 22296, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7f65630f2000
close(3)                                = 0
mprotect(0x7f65630f0000, 4096, PROT_READ) = 0
munmap(0x7f65649de000, 113913)          = 0
open("/etc/services", O_RDONLY|O_CLOEXEC) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=19605, ...}) = 0
read(3, "# Network services, Internet sty"..., 4096) = 4096
read(3, "\t\t# IPX\nipx\t\t213/udp\nimap3\t\t220/"..., 4096) = 4096
read(3, "nessus\t\t1241/tcp\t\t\t# Nessus vuln"..., 4096) = 4096
close(3)                                = 0
rt_sigaction(SIGPIPE, {SIG_IGN, [PIPE], SA_RESTORER|SA_RESTART, 0x7f65633564b0}, {SIG_DFL, [], 0}, 8) = 0
open("/usr/lib/locale/locale-archive", O_RDONLY|O_CLOEXEC) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=4763056, ...}) = 0
mmap(NULL, 4763056, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7f6562a5b000
close(3)                                = 0
stat("/usr/local/mysql/share/charsets/Index.xml", {st_mode=S_IFREG|0644, st_size=18710, ...}) = 0
open("/usr/local/mysql/share/charsets/Index.xml", O_RDONLY) = 3
read(3, "<?xml version='1.0' encoding=\"ut"..., 18710) = 18710
close(3)                                = 0
futex(0xa4bfe0, FUTEX_WAKE_PRIVATE, 2147483647) = 0
socket(PF_INET, SOCK_STREAM, IPPROTO_TCP) = 3
connect(3, {sa_family=AF_INET, sin_port=htons(3306), sin_addr=inet_addr("127.0.0.1")}, 16) = 0
setsockopt(3, SOL_TCP, TCP_NODELAY, [1], 4) = 0
setsockopt(3, SOL_SOCKET, SO_KEEPALIVE, [1], 4) = 0
recvfrom(3, "J\0\0\0\n5.7.18\0\20\0\0\0[\\F\16Y7\177^\0\377\377\10\2\0\377\301"..., 16384, 0, NULL, NULL) = 78
sendto(3, " \0\0\1\205\256\377\1\0\0\0\1!\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 36, 0, NULL, 0) = 36
open("/dev/urandom", O_RDONLY)          = 4
read(4, "\315Mo\221\253\t\220\277\v\310\376\331g9\314\250\276X\226\205\336A\253\260>z\241\325\333m\244\353", 32) = 32
open("/dev/urandom", O_RDONLY)          = 5
read(5, "\332\337E\20\377\202\237-X\237\317\313\323\264\35LK\344k\365\t\351\244\267\33:6\247\304\30\300\\", 32) = 32
futex(0xa4c910, FUTEX_WAKE_PRIVATE, 2147483647) = 0
sendto(3, "\26\3\2\0K\1\0\0G\3\2\254y\243\"\274\202(\243\353Zf\271\364\f\365\6\30\356\23\365-"..., 80, 0, NULL, 0) = 80
ioctl(3, FIONREAD, [0])                 = 0
recvfrom(3, "\26\3\2\0J\2\0\0F\3\2\242\304\350\3671\247\271\260\274b\257\357\4\1)\266\305)\3130|"..., 64, 0, NULL, NULL) = 64
ioctl(3, FIONREAD, [1595])              = 0
recvfrom(3, "\363\275k\205\223\n\177\26\nm\300\272\0009\0\26\3\2\2\376\v\0\2\372\0\2\367\0\2\3640\202"..., 1595, 0, NULL, NULL) = 1595
open("/etc/localtime", O_RDONLY|O_CLOEXEC) = 6
fstat(6, {st_mode=S_IFREG|0644, st_size=414, ...}) = 0
fstat(6, {st_mode=S_IFREG|0644, st_size=414, ...}) = 0
read(6, "TZif2\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\3\0\0\0\3\0\0\0\0"..., 4096) = 414
lseek(6, -249, SEEK_CUR)                = 165
read(6, "TZif2\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\3\0\0\0\3\0\0\0\0"..., 4096) = 249
close(6)                                = 0
sendto(3, "\26\3\2\0\7\v\0\0\3\0\0\0\26\3\2\1\6\20\0\1\2\1\0'\307\2404R\342\225n\30"..., 354, 0, NULL, 0) = 354
ioctl(3, FIONREAD, [75])                = 0
recvfrom(3, "\24\3\2\0\1\1\26\3\2\0@\16@\321&u\307Gn\202\363\305Y\225l\2670\374'\207G\213"..., 75, 0, NULL, NULL) = 75
sendto(3, "\27\3\2\0\360\320\317\210+\317\n\374\6\270\2438m\2;.\244n\364V\322/=\260\225\202J#"..., 245, 0, NULL, 0) = 245
ioctl(3, FIONREAD, [0])                 = 0
recvfrom(3, "\27\3\2\0@F\333\216\22\311\355b`\212\245\335#\330`-1\320\303\236\317\344\2231\371M\332\374"..., 64, 0, NULL, NULL) = 64
ioctl(3, FIONREAD, [5])                 = 0
recvfrom(3, "0\35\216\351\223", 5, 0, NULL, NULL) = 5
rt_sigaction(SIGINT, {0x410da0, [INT], SA_RESTORER|SA_RESTART, 0x7f65633564b0}, {SIG_DFL, [], 0}, 8) = 0
rt_sigaction(SIGQUIT, {0x411d90, [QUIT], SA_RESTORER|SA_RESTART, 0x7f65633564b0}, {SIG_DFL, [], 0}, 8) = 0
rt_sigaction(SIGHUP, {0x4120c0, [HUP], SA_RESTORER|SA_RESTART, 0x7f65633564b0}, {SIG_DFL, [], 0}, 8) = 0
rt_sigaction(SIGWINCH, {0x411940, [WINCH], SA_RESTORER|SA_RESTART, 0x7f65633564b0}, {SIG_DFL, [], 0}, 8) = 0
ioctl(0, TIOCGWINSZ, {ws_row=24, ws_col=80, ws_xpixel=0, ws_ypixel=0}) = 0
fstat(1, {st_mode=S_IFCHR|0620, st_rdev=makedev(136, 1), ...}) = 0
write(1, "Welcome to the MySQL monitor.  C"..., 58Welcome to the MySQL monitor.  Commands end with ; or \g.
) = 58
sendto(3, "\27\3\2\0P\373\234Q\34\365)\377\375#\372\242f\211\236b<<\"R2m\202\234\203\243E9"..., 85, 0, NULL, 0) = 85
ioctl(3, FIONREAD, [149])               = 0
recvfrom(3, "\27\3\2\0\220~\360Z\0n\345\215\307[l\271dZ\343\237\360\244\330!w>r|!\304\356("..., 149, 0, NULL, NULL) = 149
write(1, "Your MySQL connection id is 16\nS"..., 83Your MySQL connection id is 16
Server version: 5.7.18 MySQL Community Server (GPL)
) = 83
write(1, "\n", 1
)                       = 1
write(1, "Copyright (c) 2000, 2017, Oracle"..., 214Copyright (c) 2000, 2017, 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.
) = 214
write(1, "\n", 1
)                       = 1
readlink("/home/sunqingyao/.mysql_history", 0x7ffc05538020, 511) = -1 EINVAL (Invalid argument)
ioctl(0, TCGETS, {B38400 opost isig icanon echo ...}) = 0
open("/usr/lib/x86_64-linux-gnu/gconv/gconv-modules.cache", O_RDONLY) = 6
fstat(6, {st_mode=S_IFREG|0644, st_size=26258, ...}) = 0
mmap(NULL, 26258, PROT_READ, MAP_SHARED, 6, 0) = 0x7f65649f3000
close(6)                                = 0
futex(0x7f65636e68c8, FUTEX_WAKE_PRIVATE, 2147483647) = 0
rt_sigprocmask(SIG_BLOCK, [WINCH], [], 8) = 0
ioctl(1, TCGETS, {B38400 opost isig icanon echo ...}) = 0
stat("/home/sunqingyao/.terminfo", 0x1d0f230) = -1 ENOENT (No such file or directory)
stat("/etc/terminfo", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
stat("/lib/terminfo", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
stat("/usr/share/terminfo", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
access("/etc/terminfo/x/xterm-256color", R_OK) = -1 ENOENT (No such file or directory)
access("/lib/terminfo/x/xterm-256color", R_OK) = 0
open("/lib/terminfo/x/xterm-256color", O_RDONLY) = 6
fstat(6, {st_mode=S_IFREG|0644, st_size=3417, ...}) = 0
read(6, "\32\1%\0&\0\17\0\235\1\262\5xterm-256color|xterm"..., 4096) = 3417
read(6, "", 4096)                       = 0
close(6)                                = 0
ioctl(1, TCGETS, {B38400 opost isig icanon echo ...}) = 0
ioctl(1, TCGETS, {B38400 opost isig icanon echo ...}) = 0
ioctl(1, TIOCGWINSZ, {ws_row=24, ws_col=80, ws_xpixel=0, ws_ypixel=0}) = 0
ioctl(0, TIOCGWINSZ, {ws_row=24, ws_col=80, ws_xpixel=0, ws_ypixel=0}) = 0
rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
ioctl(1, TCGETS, {B38400 opost isig icanon echo ...}) = 0
ioctl(0, TCGETS, {B38400 opost isig icanon echo ...}) = 0
ioctl(0, TCGETS, {B38400 opost isig icanon echo ...}) = 0
ioctl(0, SNDCTL_TMR_STOP or TCSETSW, {B38400 opost isig icanon echo ...}) = 0
ioctl(0, TCGETS, {B38400 opost isig icanon echo ...}) = 0
brk(0x1d46000)                          = 0x1d46000
rt_sigprocmask(SIG_BLOCK, [HUP INT QUIT TERM CONT TSTP WINCH], [], 8) = 0
rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
getuid()                                = 1000
geteuid()                               = 1000
getgid()                                = 1000
getegid()                               = 1000
open("/home/sunqingyao/.editrc", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/home/sunqingyao/.mysql_history", O_RDONLY) = 6
fstat(6, {st_mode=S_IFREG|0600, st_size=734, ...}) = 0
read(6, "_HiStOrY_V2_\nSELECT\\040User,\\040"..., 4096) = 734
read(6, "", 4096)                       = 0
close(6)                                = 0
write(1, "Type 'help;' or '\\h' for help. T"..., 79Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
) = 79
write(1, "\n", 1
)                       = 1
stat("/etc/localtime", {st_mode=S_IFREG|0644, st_size=414, ...}) = 0
rt_sigprocmask(SIG_BLOCK, [HUP INT QUIT TERM CONT TSTP WINCH], [], 8) = 0
rt_sigaction(SIGINT, {0x4c0820, [], SA_RESTORER, 0x7f65645cb390}, {0x410da0, [INT], SA_RESTORER|SA_RESTART, 0x7f65633564b0}, 8) = 0
rt_sigaction(SIGTSTP, {0x4c0820, [], SA_RESTORER, 0x7f65645cb390}, {SIG_DFL, [], 0}, 8) = 0
rt_sigaction(SIGQUIT, {0x4c0820, [], SA_RESTORER, 0x7f65645cb390}, {0x411d90, [QUIT], SA_RESTORER|SA_RESTART, 0x7f65633564b0}, 8) = 0
rt_sigaction(SIGHUP, {0x4c0820, [], SA_RESTORER, 0x7f65645cb390}, {0x4120c0, [HUP], SA_RESTORER|SA_RESTART, 0x7f65633564b0}, 8) = 0
rt_sigaction(SIGTERM, {0x4c0820, [], SA_RESTORER, 0x7f65645cb390}, {SIG_DFL, [], 0}, 8) = 0
rt_sigaction(SIGCONT, {0x4c0820, [], SA_RESTORER, 0x7f65645cb390}, {SIG_DFL, [], 0}, 8) = 0
rt_sigaction(SIGWINCH, {0x4c0820, [], SA_RESTORER, 0x7f65645cb390}, {0x411940, [WINCH], SA_RESTORER|SA_RESTART, 0x7f65633564b0}, 8) = 0
rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
rt_sigprocmask(SIG_BLOCK, [WINCH], [], 8) = 0
ioctl(0, TIOCGWINSZ, {ws_row=24, ws_col=80, ws_xpixel=0, ws_ypixel=0}) = 0
rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
write(1, "mysql> ", 7mysql> )                  = 7
ioctl(0, TCGETS, {B38400 opost isig icanon echo ...}) = 0
ioctl(0, TCGETS, {B38400 opost isig icanon echo ...}) = 0
ioctl(0, SNDCTL_TMR_STOP or TCSETSW, {B38400 opost isig -icanon -echo ...}) = 0
ioctl(0, TCGETS, {B38400 opost isig -icanon -echo ...}) = 0
read(0, 
7
  • What happens if you use -p with the right password? Commented Jul 2, 2017 at 0:43
  • @Michael-sqlbot In that case, I'm able to log in. In other words, mysql -u root -p with the correct password is identical to mysql -u root. Commented Jul 2, 2017 at 0:48
  • 1
    Did the password somehow get added to my.cnf or .mylogin.cnf? dev.mysql.com/doc/refman/5.7/en/password-security-user.html That's what it sounds like. Commented Jul 2, 2017 at 1:00
  • @Michael-sqlbot No, I never added that manually, and I don't think any program would do this automatically. Actually, I don't even have a my.cnf file in my home directory. Commented Jul 2, 2017 at 1:19
  • You wouldn't thing that, but I wouldn't think Oracle would do a lot of the things they do to MySQL in the interest of being "helpful." I would run the mysql client with whatever the Mac equivalient of strace is -- it traces all system calls so that you can see (among other things) what files are being read. Another possibility, this is the work of the auth_socket plugin. Commented Jul 2, 2017 at 1:27

1 Answer 1

1

Run mysql_secure_installation command and enter your mysql root password, if no password just hit ENTER to skip and then you can set mysql root password at first step.

Simply press y or hit ENTER to get default options.

mysql_secure_installation Documents

Hope this help :)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.