#进入mysql,第一次进入没有密码 ~$ mysql -u root mysql> SHOW DATABASES; #查看默认的库 mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '123456'; #修改密码
#后续进入mysql或连接mysql均需要密码 ~ $ mysql -u root -p Enter password: #输入密码,不会回显 Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 16 Server version: 10.11.4-MariaDB MariaDB Server Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. MariaDB [(none)]> use mysql; #使用mysql库,带上分号结束符 Database changed MariaDB [mysql]> show tables; #显示mysql库中所有的表,带上分号结束符 +---------------------------+ | Tables_in_mysql | +---------------------------+ | column_stats | | columns_priv | | db | ...(略) 31 rows in set (0.003 sec) #GRANT命令可以修改权限,如下命令打开root用户远程连接功能,*.* 指所有库.表,% 指所有主机均可链接,123456是密码 MariaDB [mysql]> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION; MariaDB [mysql]> FLUSH PRIVILEGES; #刷新权限,使修改生效 MariaDB [mysql]> exit #退出mysql命令行,无需分号结束符 Bye