# mysql -u root -p Enter password: Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 8 Server version: 5.5.60-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)]> show variables like "%character%"; show variables like "%collation%"; +--------------------------+----------------------------+ | Variable_name | Value | +--------------------------+----------------------------+ | character_set_client | utf8 | | character_set_connection | utf8 | | character_set_database | latin1 | | character_set_filesystem | binary | | character_set_results | utf8 | | character_set_server | latin1 | | character_set_system | utf8 | | character_sets_dir | /usr/share/mysql/charsets/ | +--------------------------+----------------------------+ 8 rows in set (0.01 sec)
+----------------------+-------------------+ | Variable_name | Value | +----------------------+-------------------+ | collation_connection | utf8_general_ci | | collation_database | latin1_swedish_ci | | collation_server | latin1_swedish_ci | +----------------------+-------------------+ 3 rows in set (0.00 sec)
#配置字符集后 MariaDB [(none)]> show variables like "%character%"; show variables like "%collation%"; +--------------------------+----------------------------+ | Variable_name | Value | +--------------------------+----------------------------+ | character_set_client | utf8 | | character_set_connection | utf8 | | character_set_database | utf8 | | character_set_filesystem | binary | | character_set_results | utf8 | | character_set_server | utf8 | | character_set_system | utf8 | | character_sets_dir | /usr/share/mysql/charsets/ | +--------------------------+----------------------------+ 8 rows in set (0.00 sec)
+----------------------+-----------------+ | Variable_name | Value | +----------------------+-----------------+ | collation_connection | utf8_unicode_ci | | collation_database | utf8_unicode_ci | | collation_server | utf8_unicode_ci | +----------------------+-----------------+ 3 rows in set (0.00 sec)
远程访问数据库
MariaDB默认是拒绝root远程登录的。 先查看mysql数据库中的user表:
1 2 3 4 5 6 7 8 9 10
MariaDB [(none)]> select host,user from mysql.user; +-----------------------+------+ | host | user | +-----------------------+------+ | 127.0.0.1 | root | | ::1 | root | | localhost | root | | localhost.localdomain | root | +-----------------------+------+ 5 rows in set (0.00 sec)
127.0.0.1,::1,localhost三个都是指本机;
给root用户添加远程访问权限
1 2 3 4 5 6 7 8 9 10 11 12 13
# 所有IP都可以使用root连接;"%"表示针对所有IP,"password"表示将用这个密码登录, # 可以和本机登录root的密码不一样(root在不同IP登录,采用不一样的密码)。 MariaDB [(none)]> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'password' WITH GRANT OPTION; #只让某个IP段(192.168.1.xx)的主机连接,可以修改为"192.168.1.%"; MariaDB [(none)]> GRANT ALL PRIVILEGES ON *.* TO 'root'@'192.168.1.%' IDENTIFIED BY 'password' WITH GRANT OPTION;
#创建用户user,可远程登陆,密码为"password"; CREATE USER 'user'@'%' IDENTIFIED BY "password"; #*.*是指所有库的所有表,可以限制权限指定数据库,或指定数据库的哪些表 GRANT ALL PRIVILEGES ON *.* TO 'user'@'%' IDENTIFIED BY 'password' WITH GRANT OPTION;