CentOS 7装mysql
程序员文章站
2022-07-02 09:32:26
安装mysql
centos 7的yum源中貌似没有正常安装mysql时的mysql-sever文件,需要去官网上下载
echo "下载mysql的repo源&quo...
安装mysql
centos 7的yum源中貌似没有正常安装mysql时的mysql-sever文件,需要去官网上下载
echo "下载mysql的repo源"
wget https://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm echo "安装rpm包" rpm -ivh mysql-community-release-el7-5.noarch.rpm echo "安装mysql" yum install mysql-community-server
成功安装之后重启mysql服务
# systemctl restart mysqld.service
初次安装mysql是root账户是没有密码的.
设置密码与远程登录
1.设置root的密码为mypassword,
2.将所有操作权限授予用户 ( 用户名为power && 密码为password && 来自任何ip )
# mysql -uroot mysql> use mysql; mysql> update user set password=password('mypassword') where user='root'; mysql> grant all privileges on *.* to 'power'@'%' identified by 'password' with grant option; mysql> flush privileges; mysql> exit;
修改mysql字符集编码
vim /etc/my.cnf [mysqld] init_connect=’set collation_connection = utf8_unicode_ci’ init_connect=’set names utf8’ character-set-server=utf8 collation-server=utf8_unicode_ci [client] default-character-set=utf8 [mysql] default-character-set=utf8
防火墙规则修改
firewall-cmd --permanent --add-port=3306/tcp firewall-cmd --reload
重启mysql重载生效配置
# systemctl restart mysqld.service
登录报错:
error 2002 (hy000): can‘t connect to local mysql server through socket‘/var/lib/mysql/mysql.sock‘ (2)
原因是/var/lib/mysql的访问权限问题。下面的命令把/var/lib/mysql的拥有者改为当前用户:
$ sudo chown -r mysql:mysql /var/lib/mysql
推荐阅读