Mysql -Linux系统下安装指南
博客参考: https://www.cnblogs.com/pyyu/p/9467289.html
1. Mysql安装
1、首先在 RHEL/CentOS 和 Fedora 操作系统中添加 MariaDB 的 YUM 配置文件 MariaDB.repo 文件。 #编辑创建mariadb.repo仓库文件 vi /etc/yum.repos.d/MariaDB.repo
2、添加repo仓库配置 [mariadb] name = MariaDB baseurl = http://yum.mariadb.org/10.1/centos7-amd64 gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB gpgcheck=1
3、当 MariaDB 仓库地址添加好后,你可以通过下面的一行命令轻松安装 MariaDB。 yum install MariaDB-server MariaDB-client -y
4. mariadb数据库的相关命令是: systemctl start mariadb #启动MariaDB systemctl stop mariadb #停止MariaDB systemctl restart mariadb #重启MariaDB systemctl enable mariadb #设置开机启动
5. 启动后正常使用的mysql systemctl start mariadb
2. 初始化mysql
在确认 MariaDB 数据库软件程序安装完毕并成功启动后请不要立即使用。为了确保数据 库的安全性和正常运转,需要先对数据库程序进行初始化操作。这个初始化操作涉及下面 5 个 步骤。 ➢ 设置 root 管理员在数据库中的密码值(注意,该密码并非 root 管理员在系统中的密 码,这里的密码值默认应该为空,可直接按回车键)。 ➢ 设置 root 管理员在数据库中的专有密码。 ➢ 随后删除匿名账户,并使用 root 管理员从远程登录数据库,以确保数据库上运行的业 务的安全性。 ➢ 删除默认的测试数据库,取消测试数据库的一系列访问权限。 ➢ 刷新授权列表,让初始化的设定立即生效。
mysql_secure_installation
3. MySql基本命令
#修改mysql密码 MariaDB [(none)]> set password = PASSWORD('redhat123');
登录mysql [[email protected]_0_2_centos yum.repos.d]# mysql -uroot -p Enter password: Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 11 Server version: 10.1.37-MariaDB MariaDB Server Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. MariaDB [(none)]> Ctrl-C -- exit! Aborted [[email protected]_0_2_centos yum.repos.d]#
设置mysql
1.中文编码设置,编辑mysql配置文件/etc/my.cnf,下入以下内容 [mysqld] character-set-server=utf8 collation-server=utf8_general_ci log-error=/var/log/mysqld.log
bind-address = 0.0.0.0 #允许远端所有机器访问 [client] default-character-set=utf8 [mysql] default-character-set=utf8
2.授权配置 远程连接设置哦设置所有库,所有表的所有权限,赋值权限给所有ip地址的root用户 mysql > grant all privileges on *.* to [email protected]'%' identified by 'password'; 远端访问必须有此命令 #创建用户 mysql > create user 'username'@'%' identified by 'password'; #刷新权限 flush privileges;
数据库备份与恢复
mysqldump命令用于备份数据库数据 [[email protected] ~]# mysqldump -u root -p --all-databases > /tmp/db.dump 进入mariadb数据库,删除一个db [[email protected] ~]# mysql -uroot -p MariaDB [(none)]> drop database s11; 进行数据恢复,吧刚才重定向备份的数据库文件导入到mysql中 [[email protected] ~]# mysql -uroot -p < /tmp/db.dump
Mysql 主从复制
bind-address = 0.0.0.0