yum安装MySQL并设置密码_MySQL
yum安装MySQL并设置密码
Shell代码
yum install mysql
yum install mysql-server
yum install mysql-devel
chgrp -R mysql /var/lib/mysql
chmod -R 770 /var/lib/mysql
service mysqld start
mysql
SET PASSWORD FOR 'root'@'localhost' = PASSWORD('secret_password');
设置默认编码等一些初始参数(my.cnf)(若无my.cnf, 则可cp /usr/share/mysql/my-small.cnf /etc/my.cnf)
vi /etc/my.cnf
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
default-character-set=utf8 [添加]
default-storage-engine=INNODB [添加]
old_passwords=1
[client]
default-character-set=utf8 [添加]
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
下面就是常规的操作了:
更改 root 密码: mysqladmin -u root password 'newpassword'
添加mysql用户: GRANT ALL PRIVILEGES ON my_db.* TO 'user'@'localhost' IDENTIFIED BY'password';
删除test数据库: mysql -u root -p mysql> DROP DATABASE test;
删除匿名帐户: DELETE FROM mysql.user WHERE user = '';
重载权限: mysql> FLUSH PRIVILEGES;
如要其他机器能访问,在mysql.user中添加一个Host为'%'的user,然后flush priviledges;,最后防火墙加一句类似这样的语句即可(开通3306端口):
Shell代码
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT
如果要reboot自启动:
Shell代码
chkconfig --levels 345 mysqld on
bitsCN.com
推荐阅读
-
详解利用Dockerfile构建mysql镜像并实现数据的初始化及权限设置
-
linux 用yum命令安装mysql的步骤分享
-
CentOS7下MySQL5.7安装配置方法图文教程(YUM)
-
详解MySQL安装及MySQL8.0新密码认证方式
-
redhat7通过yum安装mysql5.7.17教程
-
Windows7下安装使用MySQL8.0.16修改密码、连接Navicat问题
-
在MySQL中修改密码及访问限制的设置方法详解
-
Window 下安装Mysql5.7.17 及设置编码为utf8的方法
-
Mysql5.7.14安装配置方法操作图文教程(密码问题解决办法)
-
Ubuntu安装MySQL5.7并配置数据存储路径的方法步骤