基于ubuntu20.04装置MySQL全过程记录
1.装置MySQL
sudo apt-get update #获取最新的软件源sudo apt-get install mysql-server #装置mysql
启动与敞开mysql
service mysql start #启动MySQLservice mysql stop #敞开MySQL
2.进行MySQL配置
启动mysql
service mysql start
为避免下一步配置时呈现设置明码出错的bug,先将root明码进行设置(倡议执行,我集体每次间接执行下一步配置时都会在明码那里报错)
sudo mysqlALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'your_password';exit
进行配置操作
sudo mysql_secure_installation
执行后依照流程进行抉择即可,如果未对root进行明码设置,此过程第二步设置明码时可能呈现报错"Failed! Error: SET PASSWORD has no significance for user 'root'@'localhost' as the authentication method used doesn't store authentication data in the MySQL server....
",倡议先返回执行上一步内容。
后续就是跟着主动配置程序的问题进行yes or no的抉择。大略内容如下:
#1.询问是否装置明码插件#2.为root用户设置明码 or 是否须要重置明码#3.是否删除匿名用户#4.是否禁止root管理员从近程登录#5.是否删除test数据库并勾销对它的拜访权限#6.是否刷新受权表,让初始化后的设定立刻失效
都选完后显示All done
查看mysql运行状态
netstat -tap | grep mysql
3.配置远程登陆(如果需要的话)
此时mysql还不容许近程登录,如果通过navicat之类的工具从其余地址进行连贯时,会报错Host is not allowed to connect to this MySQL server
,如果业务有需要的话,须要进行放开操作。
首先登陆mysql
mysql -u root -p
输出明码后进入mysql命令中,执行以下内容
#关上mysql库use mysql#查看拜访域设置select host from user where user = 'root';#批改拜访域,将localhost改为%update user set host ='%' where user = 'root';#从新加载权限flush privileges;#退出exit
批改mysql配置文件中的绑定ip
vim /etc/mysql/mysql.conf.d/mysqld.conf
找到外面的bind-address = 127.0.0.1
这一行,将它正文掉,保留退出。
重启mysql
service mysql stopservice mysql start