Ubuntu下MySQL Server安装

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/csfyx/article/details/85336987

        公司业务需要安装MySQL,安装过程比较简单,但是在配置连接的中途遇到了不少坑,特此记录下来。
        一、安装:
              sudo apt-get update sudo apt-get install mysql-server
              sudo apt-get install mysql-client
              sudo apt-get install libmysqlclient-dev         

        二、配置:
              1、启动 /etc/inint.d/mysql start
              2、停止 /etc/inint.d/mysql stop
              3、重启 /etc/inint.d/mysql restart

        三、连接:

              在mysql server启动后通过mysql -u(用户名) -p(密码)连接的时候出现了以下错误:
                    ERROR 2003 (HY000): Can't connect to MySQL server on '*.*.*.*' (111)
              出现这个问题是因为配置文件中有bind_address=127.0.0.1 ,只能本地登录,需要修改my.cnf解决:
                    1、vim /etc/mysql/my.cnf
                    2、注释掉bind-address = 127.0.0.1
                    3、/etc/init.d/mysql restart
              屏蔽掉之后客户端再次连接又出现:
                    ERROR 1130 (HY000): Host '*.*.*.*' is not allowed to connect to this MySQL server
              这个问题是因为外部ip地址访问数据库并没有权限,需要让数据库给其分配权限,在本地登录mysql,执行
                    1、设定指定ip能够访问mysql:
                                     GRANT ALL PRIVILEGES ON *.* TO 'user'@'hostip' IDENTIFIED BY 'password' WITH GRANT OPTION;
                          设定所有外部ip访问mysql:
                                     GRANT ALL PRIVILEGES ON *.* TO 'user'@'%' IDENTIFIED BY 'password' WITH GRANT OPTION;
                    2、刷新数据库:
                          flush privileges;
                    3、退出数据库并重启服务:
                           exit;
                           /etc/inint.d/mysql restart
              修改之后客户端再次连接又出现:
                    ERROR 1045 (28000): Access denied for user 'root'@'116.136.19.94' (using password: YES)
              一般这个错误是由密码错误引起,可是这儿本地登录没有问题,也就是不存在密码错误的问题,其实是因为MySQL在外部ip强制在第一次登陆时修改root用户的密码,解决方案如下:
                    1、直接不使用密码登录:
                            /etc/mysql/my.cnf 中[mysqld]字段下添加
                            skip-grant-tables
                            这样可以通过mysql -uroot -p 直接登陆没有密码
                    2、重置密码:
                            use mysql;
                            desc user;//这里设置的时候一定先看看字段名字,下边设置需要根据这个字段设置,不同版本有区别
                            update user set Password=password('hadoop') where User='root';
                            update user set host='%' where User='root'
                            flush privileges;

              折腾了这么几轮,再次连接正常进入数据库。

猜你喜欢

转载自blog.csdn.net/csfyx/article/details/85336987