Ubuntu18.04(linux)安装MySQL的方法步骤
安装
mysql
sudoapt-get--purgeremovemysql-servermysql-commonmysql-client sudoapt-getinstallmysql-servermysql-commonmysql-client mysqladmin-urootpasswordyour-new-password sudo/etc/init.d/mysqlrestart
mariadb
apt-getinstallmariadb-server
字符集修改utf8
如果装的mariadb,默认字符集已经是utf8了。mysql则不是
mysql>showvariableslike'char%'; +--------------------------+----------------------------+ |Variable_name|Value| +--------------------------+----------------------------+ |character_set_client|utf8| |character_set_connection|utf8| |character_set_database|latin1| |character_set_filesystem|binary| |character_set_results|utf8| |character_set_server|latin1| |character_set_system|utf8| |character_sets_dir|/usr/share/mysql/charsets/| +--------------------------+----------------------------+
mysql>showvariableslike'collation%'; +----------------------+-------------------+ |Variable_name|Value| +----------------------+-------------------+ |collation_connection|utf8_general_ci| |collation_database|latin1_swedish_ci| |collation_server|latin1_swedish_ci| +----------------------+-------------------+
修改字符集:
sudovim/etc/mysql/my.cnf
添加以下内容
[mysqld] collation-server=utf8_unicode_ci init-connect='SETNAMESutf8' character-set-server=utf8
重启:
servicemysqlrestart
登录权限问题
Ubuntu18.04安装mysql或者mariadb之后,发现普通用户和远程都没有权限连接。
ERROR1045:Accessdeniedforuser:'root@localhost'(Using
password:YES)
修改了密码也不对。然后sudomysql-uroot即可登录。这显然不是我们想要的。
解决方案
删除root,重新创建用户。
首先,登录
sudomysql-uroot
然后查看当前用户
SELECTUser,HostFROMmysql.user; +------------------+-----------+ |User|Host| +------------------+-----------+ |admin|localhost| |debian-sys-maint|localhost| |magento_user|localhost| |mysql.sys|localhost| |root|localhost|
删除root账号
mysql>DROPUSER'root'@'localhost'; QueryOK,0rowsaffected(0,00sec)
重新创建root:
mysql>CREATEUSER'root'@'%'IDENTIFIEDBY'123456'; QueryOK,0rowsaffected(0,00sec)
授权
mysql>GRANTALLPRIVILEGESON*.*TO'root'@'%'WITHGRANTOPTION; QueryOK,0rowsaffected(0,00sec) mysql>FLUSHPRIVILEGES; QueryOK,0rowsaffected(0,01sec)
关于重置密码
host为%时允许远程登录
SETPASSWORDFORroot@'localhost'=PASSWORD('password');
or
UPDATEmysql.userSETPassword=PASSWORD('newpwd')WHEREUser='root';
or
USEmysql UPDATEuserSETPassword=PASSWORD('newpwd') WHEREHost='localhost'ANDUser='root';
允许任何地方登录
USEmysql UPDATEuserSETPassword=PASSWORD('newpwd') WHEREHost='%'ANDUser='root';
参考
https://askubuntu.com/questions/766334/cant-login-as-mysql-user-root-from-normal-user-account-in-ubuntu-16-04
https://help.ubuntu.com/community/MysqlPasswordReset
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持毛票票。