当前位置:   article > 正文

ubuntu以apt方式安装mysql,并设置自启动_ubuntu安装解压版myql开机自启

ubuntu安装解压版myql开机自启

检查mysql服务状态:

systemctl status mysql
  • 1

查看有没有安装MySQL:

  dpkg -l | grep mysql
  • 1

查找合适的mysql版本:

apt-cache search mysql-server
  • 1

安装MySQL:

  apt install mysql-server -y
  • 1

安装完成之后可以使用如下命令来检查是否安装成功:

netstat -tap | grep mysql
  • 1

看到有 mysql 的socket处于 LISTEN 状态则表示安装成功
在这里插入图片描述
到这里已经数据库已经安装成功,并且可以使用,且没有密码
登录mysql数据库可以通过如下命令:

mysql -u root -p
  • 1

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

密码查看

cat /etc/mysql/debian.cnf
  • 1

在这里插入图片描述

#数据库初始化

mysql_secure_installation
  • 1

输出

Securing the MySQL server deployment.

Connecting to MySQL using a blank password.

VALIDATE PASSWORD COMPONENT can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD component?    #要安装验证密码插件吗?

Press y|Y for Yes, any other key for No: y

There are three levels of password validation policy:

LOW    Length >= 8
MEDIUM Length >= 8, numeric, mixed case, and special characters
STRONG Length >= 8, numeric, mixed case, special characters and dictionary                  file

Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 2    #选择密码强度
Please set the password for root here.

New password:  #输入新密码
Re-enter new password: #再次输入密码

Estimated strength of the password: 100 
Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : y    #您想继续使用提供的密码吗?(按y | y表示是,按任何其他键表示否)
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL 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? (Press y|Y for Yes, any other key for No) : 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? (Press y|Y for Yes, any other key for No) : n    #禁止root管理员从远程登录

 ... skipping.
By default, MySQL 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? (Press y|Y for Yes, any other key for No) : y   #删除test数据库并取消对它的访问权限

 - 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? (Press y|Y for Yes, any other key for No) : y    #刷新授权表,让初始化后的设定立即生效

Success.

All done! 
#初始化结束
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66

检查mysql服务状态:

systemctl status mysql
  • 1

配置mysql允许远程访问

netstat -an | grep 3306
  • 1

在这里插入图片描述

说明mysql端口目前只监听本地连接127.0.0.1。然后需要修改mysql的配置文件

首先编辑 /etc/mysql/mysql.conf.d/mysqld.cnf 配置文件:

 vim /etc/mysql/mysql.conf.d/mysqld.cnf 
  • 1

注释掉

bind-address = 127.0.0.1
  • 1

进入mysql数据库,执行授权命令:

mysql -u root -p
  • 1
#mysql8之前版本执行下边语句
mysql> grant all on *.* to root@'%' identified by '你的密码' with grant option;

#mysql8之后版本执行下边语句
mysql>create user root@'%' identified by '你的密码';
 
mysql>grant all privileges on *.* to root@'%' with grant option;
#都执行刷新权限并退出
mysql> flush privileges;

mysql> quit
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11

重启mysql

sudo service mysql restart  
  • 1
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/繁依Fanyi0/article/detail/187902
推荐阅读
相关标签
  

闽ICP备14008679号