欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  数据库

yum安装MySQL并设置密码_MySQL

程序员文章站 2022-04-07 22:05:28
...
bitsCN.com

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
相关标签: 密码