您的位置:首页 > 数据库 > MariaDB

XUBUNTU下安装配置mysql或mariadb,以及workbench远程连接数据库服务

2017-04-03 21:36 971 查看
安装mysql或mariadb

由于xubuntu上装了mariadb,不论系统还是应用都略非主流

特此记录配置过程


不废话 选mariadb


sudo apt-get install mariadb-common mariadb-client mariadb-server

怕出错麻烦的可以

sudo apt-get install mariadb*

启动

sudo systemctl start mariadb



service mysql start
开始初始化配置

mysql_secure_installation  

Enter current password for root (enter for none): 当前无密码 直接回车

New password: 为root用户设置数据库密码

Re-enter new password:确认密码

Remove anonymous users? [Y/n] y  删除匿名帐号

Disallow root login remotely? [Y/n] y  禁止root用户从远程登录

Remove test database and access to it? [Y/n] y   删除test数据库并取消对其的访问权限

 Reload privilege tables now? [Y/n] y    刷新授权表,让初始化后的设定立即生效  

 

登录数据库

mysql -u root -p

输入root登录密码

进入

MariaDB [(none)]>

开始创建用户

创建数据库用户的命令:CREATE USER 用户名@主机名 IDENTIFIED BY '密码';

MariaDB [(none)]> create user sky92@localhost  IDENTIFIED BY 'xxx';

MariaDB [(none)]> exit

退出

登录刚才创建的用户

mysql -u sky92 -p

然后输入密码

远程连接前服务端的配置

停止mysql服务

sudo service mysql stop

编辑配置文件 (这个位置在debian系的mariadb中和RH的不同)

sudo nano /etc/mysql/mariadb.conf.d/50-server.cnf

找到[mysqld]下

找到

bind-address = 127.0.0.1

skip-networking

注释掉改行

#bind-address = 127.0.0.1

#skip-networking

保存退出

然后使用root登录

mysql -u root -p

输入密码后 输入执行下部语句

MariaDB [(none)]> GRANT ALL PRIVILEGES ON *.* TO 'root'@'192.168.%.%' IDENTIFIED BY 'my-new-password' WITH GRANT OPTION;

该语句允许所有用户远程以root在192.168.x.x网段中登录数据库  

同样可以用对sky92用户一样操作

exit退出

 
客户端使用mysql-workbench远程连接

sudo usr/bin/mysql-workbench

输入服务端IP  默认端口3306

sky92或者root

然后连接

错误问题参考连接

1044

mysql -u root -p 

GRANT ALL PRIVILEGES ON *.* TO 'sky92'@localhost IDENTIFIED BY 'password' WITH GRANT OPTI
4000
ON;

1045

http://www.linuxidc.com/Linux/2017-03/141240.htm

 1698

http://blog.csdn.net/ryshiki/article/details/50459008

之前MySQL服务端本机上使用密码登陆root账号是没有问题的,但是今天不知道是因为动了哪里,登陆失败并有这个错误代码:

~$ mysql -u root -p
Enter password:
ERROR 1698 (28000): Access denied for user 'root'@'localhost'


  

解决步骤:

停止mysql服务

~$ sudo service mysql stop


 

以安全模式启动MySQL

~$ sudo mysqld_safe --skip-grant-tables &


 

MySQL启动之后就可以不用密码登陆了

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


 

查看一下user表,错误的起因就是在这里, root的plugin被修改成了auth_socket,用密码登陆的plugin应该是mysql_native_password。

mysql> select user, plugin from mysql.user;
+-----------+-----------------------+
| user      | plugin                |
+-----------+-----------------------+
| root      | auth_socket           |
| mysql.sys | mysql_native_password |
| dev       | mysql_native_password |
+-----------+-----------------------+
3 rows in set (0.01 sec)


 

关于auth_socket,在官方有说明: https://dev.mysql.com/doc/mysql-security-excerpt/5.5/en/socket-authentication-plugin.html ,反正现在暂时不用它,
那就把这里改了。

mysql> update mysql.user set authentication_string=PASSWORD('newPwd'), plugin='mysql_native_password' where user='root';
Query OK, 1 row affected, 1 warning (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 1

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)


 

重启服务,问题就解决了

~$ sudo service mysql stop
...
* MySQL Community Server 5.7.10 is stopped
~$ sudo service mysql start
..
* MySQL Community Server 5.7.10 is started
~$ mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.10 MySQL Community Server (GPL)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
相关文章推荐