- 1. Mysql数据库的安装与初始化
1.1 Mysql安装
安装Mysql:
$ cd /usr/local/
//查询出已安装的mariadb
$ rpm -qa|grep mariadb
$ rpm -e --nodeps 文件名
$ rm /etc/my.cnf
执行以下命令来创建mysql用户组
$ groupadd mysql
执行以下命令来创建一个用户名为mysql的用户并加入mysql用户组
$ useradd -g mysql mysql
$ mkdir /usr/local/mysql
$ mkdir /usr/local/mysqldata
$ tar -xvf mysql-5.7.21-linux-glibc2.12-x86_64.tar.gz
$ mv mysql-5.7.21-linux-glibc2.12-x86_64 ../mysql
// 如果my.cnf 不存在,则创建,并将下面的配置粘贴入配置文件。
$ vi /etc/my.cnf
参数说明:
[mysql]
# 设置mysql客户端默认字符集
default-character-set=utf8
socket=/usr/local/mysql/mysql.sock
[mysqld]
skip-name-resolve
#设置3306端口
port=3306
socket=/usr/local/mysql/mysql.sock
# 设置mysql的安装目录
basedir=/usr/local/mysql
# 设置mysql数据库的数据的存放目录
datadir=/usr/local/mysqldata
#日志
log=/usr/local/mysql/log/mysql.log
# 允许最大连接数
max_connections=200
# 服务端使用的字符集默认为8比特编码的latin1字符集
character-set-server=utf8
# 创建新表时将使用的默认存储引擎
default-storage-engine=INNODB
# 表名不区分大小写
lower_case_table_names=1
user=mysql
Please read "Security" section of the manual to find out how to run mysqld as root!错误解决 https://blog.csdn.net/jubincn/article/details/6725582 |
赋权:
cd /usr/local/
chown -R mysql:mysql /usr/local/mysql
chown -R mysql:mysql /usr/local/mysqldata
chown 777 /etc/my.cnf
进入安装mysql软件目录
cd /usr/local/mysql
yum -y install numactl.x86_64
./bin/mysqld --initialize --user=mysql
此时会生成随机密码,进行记录。
设置开机自启动服务控制脚本
cp mysql/support-files/mysql.server /etc/rc.d/init.d/mysqld
增加mysqld服务控制脚本执行权限
chmod +x /etc/rc.d/init.d/mysqld
将mysqld服务加入到系统服务
chkconfig --add mysqld
检查mysqld服务是否已经生效
chkconfig --list mysqld
增加环境变量
vi ~/.bash_profile
vim /etc/profile
增加 export PATH=$PATH:/usr/local/mysql/bin
source ~/.bash_profile
source /etc/profile
启动mysql
$ systemctl start mysqld
$ service mysqld start
查mysql运行行状态
$ systemctl status mysqld
$ service mysqld stop
现如下状态则说明mysql已经启动
[[email protected] ~]# service mysqld stop Shutting down MySQL.. SUCCESS! [[email protected] ~]# service mysqld start Starting MySQL. SUCCESS! |
查看默认密码:
$ grep ‘temporary password‘ /usr/local/mysql/mysqld.log
修改数据库密码:
登录入数据库
$mysql
-uroot-p+自动生成的密码
设置新密码
$ setpassword
for‘root‘
@
‘localhost‘=password(
‘MyNewPass4!‘);
==== 外部客户端访问
配置ip地址;添加3306端口
[[email protected] bin]# vim /etc/sysconfig/iptables 1 # Firewall configuration written by system-config-firewall 2 # Manual customization of this file is not recommended. 3 *filter 4 :INPUT ACCEPT [0:0] 5 :FORWARD ACCEPT [0:0] 6 :OUTPUT ACCEPT [0:0] 7 -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT 8 -A INPUT -p icmp -j ACCEPT 9 -A INPUT -i lo -j ACCEPT 10 -A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT 11 -A INPUT -m state --state NEW -m tcp -p tcp --dport 21 -j ACCEPT 12 13 -A INPUT -m state --state NEW -m tcp -p tcp --dport 3333 -j ACCEPT 14 -A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT 15 16 # redis port. 17 -A INPUT -m state --state NEW -m tcp -p tcp --dport 6379 -j ACCEPT 18 -A INPUT -m state --state NEW -m tcp -p tcp --dport 6380 -j ACCEPT 19 -A INPUT -m state --state NEW -m tcp -p tcp --dport 6381 -j ACCEPT 20 21 # redis cluster. 22 -A INPUT -m state --state NEW -m tcp -p tcp --dport 8081 -j ACCEPT 23 -A INPUT -m state --state NEW -m tcp -p tcp --dport 8082 -j ACCEPT 24 -A INPUT -m state --state NEW -m tcp -p tcp --dport 8083 -j ACCEPT 25 -A INPUT -m state --state NEW -m tcp -p tcp --dport 8084 -j ACCEPT 26 -A INPUT -m state --state NEW -m tcp -p tcp --dport 8085 -j ACCEPT 27 -A INPUT -m state --state NEW -m tcp -p tcp --dport 8086 -j ACCEPT 28 29 -A INPUT -j REJECT --reject-with icmp-host-prohibited 30 -A FORWARD -j REJECT --reject-with icmp-host-prohibited 31 COMMIT 32 |
2、授权用户访问权限
https://blog.csdn.net/dongdong9223/article/details/77854690 -当然,如果想给所有ip都赋予权限,则这样: grant all privileges on *.* to ‘root‘@‘%‘ identified by ‘123456‘; -使授权立即生效
|
原文地址:https://www.cnblogs.com/hfultrastrong/p/9307969.html