ubuntu安装mysql
1、#检查有没有装置MySQL:
dpkg-l|grepmysql
2、装置MySQL:
sudoaptinstallmysql-server
3、检查是否装置成功:
netstat-tap|grepmysql
经过上述指令检查之后,假如看到有mysql的socket处于LISTEN状况则表明装置成功。
4、登录mysql数据库能够经过如下指令:
mysql-uroot-p
-u表明挑选登陆的用户名,-p表明登陆的用户暗码,现在是mysql数据库是没有暗码的,Enterpassword:处直接回车,就能够进入mysql数据库。
然后经过showdatabases;就能够检查当时的所有数据库。
5、初始化数据库
为了确保数据库的安全性和正常运转,对数据库进行初始化操作。这个初始化操作涉及下面5个步骤。
(1)装置验证暗码插件。
(2)设置root管理员在数据库中的专有暗码。
(3)随后删去匿名账户,并使用root管理员从长途登录数据库,以确保数据库上运转的业务的安全性。
(4)删去默许的测验数据库,撤销测验数据库的一系列拜访权限。
(5)改写授权列表,让初始化的设定立即收效。
root@ubuntu-virtual-machine:~#mysql_secure_installation
SecuringtheMySQLserverdeployment.
ConnectingtoMySQLusingablankpassword.
VALIDATEPASSWORDPLUGINcanbeusedtotestpasswords
andimprovesecurity.Itchecksthestrengthofpassword
andallowstheuserstosetonlythosepasswordswhichare
secureenough.WouldyouliketosetupVALIDATEPASSWORDplugin?#要装置验证暗码插件吗?
Pressy|YforYes,anyotherkeyforNo:N#这儿我挑选N
Pleasesetthepasswordforroothere.
Newpassword:#输入要为root管理员设置的数据库暗码
Re-enternewpassword:#再次输入暗码
Bydefault,aMySQLinstallationhasananonymoususer,
allowinganyonetologintoMySQLwithouthavingtohave
auseraccountcreatedforthem.Thisisintendedonlyfor
testing,andtomaketheinstallationgoabitsmoother.
Youshouldremovethembeforemovingintoaproduction
environment.
Removeanonymoususers?(Pressy|YforYes,anyotherkeyforNo):y#删去匿名账户
Success.
Normally,rootshouldonlybeallowedtoconnectfrom
‘localhost’.Thisensuresthatsomeonecannotguessat
therootpasswordfromthenetwork.
Disallowrootloginremotely?(Pressy|YforYes,anyotherkeyforNo):#制止root管理员从长途登录,这儿我没有制止
…skipping.
Bydefault,MySQLcomeswithadatabasenamed’test’that
anyonecanaccess.Thisisalsointendedonlyfortesting,
andshouldberemovedbeforemovingintoaproduction
environment.
Removetestdatabaseandaccesstoit?(Pressy|YforYes,anyotherkeyforNo):y#删去test数据库并撤销对它的拜访权限
-Droppingtestdatabase…
Success.
-Removingprivilegesontestdatabase…
Success.
Reloadingtheprivilegetableswillensurethatallchanges
madesofarwilltakeeffectimmediately.
Reloadprivilegetablesnow?(Pressy|YforYes,anyotherkeyforNo):y#改写授权表,让初始化后的设定立即收效
Success.
Alldone!
6、检查mysql服务状况:
systemctlstatusmysql
显现如下结果阐明mysql服务运转是正常的:
再次用mysql-uroot-p指令,Enterpassword:处输入刚设置的暗码,回车,就能够进入mysql数据库。
使用usemysql;指令打开mysql命名的数据库,显现当时数据库的表:showtables;查询user表里的数据:select*fromuser;(user表里是mysql数据库的所有账户信息)
7、装备mysql答应长途拜访,首要修改/etc/mysql/mysql.conf.d/mysqld.cnf装备文件:
vim/etc/mysql/mysql.conf.d/mysqld.cnf
注释掉bind-address=127.0.0.1
8、保存退出,然后进入mysql数据库,执行授权指令:
mysql-uroot-p
mysql>grantallon*.*toroot@’%’identifiedby’你的暗码’withgrantoption;
mysql>flushprivileges;#改写权限
mysql>exit
然后执行exit指令退出mysql服务,再执行如下指令重启mysql:
systemctlrestartmysql
现在Windows下能够使用Navicat图形化工具长途连接Ubuntu下的MySQL数据库,输入刚授权长途权限的暗码。
9、修正数据库端口
使用指令showglobalvariableslike’port’;检查端口号
修改/etc/mysql/mysql.conf.d/mysqld.cnf文件
vi/etc/mysql/mysql.conf.d/mysqld.cnf
在文件中添加port参数,port=13306样式来进行修正端口,如下图
10、重新启动mysql
systemctlrestartmysql
11、检查端口
在SQL中执行指令:
showglobalvariableslike’port’;
mysql查看所有用户
一、查看一切用户
在MySQL中有一个内置名为mysql的数据库,这个数据库中存储的是MySQL的一些数据,比如用户、权限信息、存储过程等。所以咱们能够通过如下查询句子来查看一切用户。
mysql>SELECTDISTINCTCONCAT(‘User:”’,user,”’@”’,host,”’;’)ASqueryFROMmysql.user;
mysql>SELECTUser,Host,PasswordFROMmysql.user;
mysql>SELECTDISTINCTUserFROMmysql.user;
二、查看当前登陆用户
mysql>SELECTuser();
mysql>SELECTcurrent_user();//括号能够不要
评论前必须登录!
注册