美文网首页数据库
在树莓派系统中安装MySQL数据库

在树莓派系统中安装MySQL数据库

作者: 测绘小兵 | 来源:发表于2019-11-18 22:23 被阅读0次


    1、查看是否已安装mysql数据库或运行

    netstat -tap | grep mysql

    或者dpkg -l | grep mysql

    或者systemctl status mysql


    2、安装mysql数据库

    sudo apt-get install mysql-server


    3、登录mysql数据库(第一次)

    sudo mysql -u root

    -u 表示选择登陆的用户名,现在是mysql数据库是没有密码的,Enter password:处直接回车,就能够进入mysql数据库。

    sudo mysql -u root -p

    回车提示输入密码

    -p 表示登陆的用户密码。


    4、对数据库进行初始化操作

    sudo mysql_secure_installation

    (1)安装验证密码插件。

    (2)设置root管理员在数据库中的专有密码。

    (3)随后删除匿名账户,并使用root管理员从远程登录数据库,以确保数据库上运行的业务的安全性。

    (4)删除默认的测试数据库,取消测试数据库的一系列访问权限。

    (5)刷新授权列表,让初始化的设定立即生效。

    --------------------------------------------------------------------------------------

    pi@raspberrypi:~ $ sudo mysql_secure_installation

    NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB

          SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

    In order to log into MariaDB to secure it, we'll need the current

    password for the root user.  If you've just installed MariaDB, and

    you haven't set the root password yet, the password will be blank,

    so you should just press enter here.

    Enter current password for root (enter for none):

    OK, successfully used password, moving on...

    Setting the root password ensures that nobody can log into the MariaDB

    root user without the proper authorisation.

    Set root password? [Y/n] 123456

    Set root password? [Y/n] y

    New password:

    Re-enter new password:

    Password updated successfully!

    Reloading privilege tables..

    ... Success!

    By default, a MariaDB installation has an anonymous user, allowing anyone

    to log into MariaDB without having to have a user account created for

    them.  This is intended only for testing, and to make the installation

    go a bit smoother.  You should remove them before moving into a

    production environment.

    Remove anonymous users? [Y/n] y

    ... Success!

    Normally, root should only be allowed to connect from 'localhost'.  This

    ensures that someone cannot guess at the root password from the network.

    Disallow root login remotely? [Y/n] n

    ... skipping.

    By default, MariaDB comes with a database named 'test' that anyone can

    access.  This is also intended only for testing, and should be removed

    before moving into a production environment.

    Remove test database and access to it? [Y/n] y

    - Dropping test database...

    ... Success!

    - Removing privileges on test database...

    ... Success!

    Reloading the privilege tables will ensure that all changes made so far

    will take effect immediately.

    Reload privilege tables now? [Y/n] y

    ... Success!

    Cleaning up...

    All done!  If you've completed all of the above steps, your MariaDB

    installation should now be secure.

    Thanks for using MariaDB!

    pi@raspberrypi:~ $

    ————————————————————————————————————————————————————————————————————————————————————————-


    3、查看mysql版本

    在命令行登录mysql,即可看到mysql的版本号


    5、重启mysql

    systemctl restart mysql


    6、配置mysql允许远程访问

    (1)首先编辑 /etc/mysql/mariadb.conf.d/50-server.cnf 配置文件:

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

    # 将bind-address这行注释掉

    # 或者将127.0.0.1 这个值改为  0.0.0.0

    # 然后重启

    $ sudo /etc/init.d/mysql restart

    (2)进入mysql数据库,执行授权命令

    $sudo mysql -u root -p

    $ 输入密码

    MariaDB [(none)]> use mysql;

    MariaDB [mysql]> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'root的密码' WITH GRANT OPTION;

    MariaDB [mysql]> flush privileges;


    相关文章

      网友评论

        本文标题:在树莓派系统中安装MySQL数据库

        本文链接:https://www.haomeiwen.com/subject/ncdiictx.html