欢迎投稿

今日深度:

centos7安装mysql,centos7mysql

centos7安装mysql,centos7mysql


MySQL是用于Web和服务器应用程序的流行数据库管理系统。但是,MySQL不再在CentOS的存储库中,而且MariaDB已经成为提供的默认数据库系统。MariaDB被认为是MySQL的替代品,如果您只需要一个数据库系统使用MariaDB就足够了。centos7中安装MariaDB请参阅MariaDB安装教程 本指南将介绍如何在运行CentOS 7的Linode上安装,配置和管理它。
建议:在操作本指南之前使用指令su -切换为root用户

开始之前准备

1.确保设置了主机名,检查您的主机名运行:

hostname
hostname -f

第一个命令应显示您的短主机名,第二个命令应显示您的完全限定域名(FQDN)。
2.更新系统:

yum update 

3.在操作中会使用到wget,使用如下命令安装:

yum install wget

安装MySQL

MySQL必须从社区存储库中中安装。
1.下载并添加存储库,然后更新。

wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm
rpm -ivh mysql-community-release-el7-5.noarch.rpm
yum update

2.安装MySQL并启动服务。在安装过程中,系统会询问您是否接受.rpm文件的GPG验证结果。如果没有发生错误或不匹配,请输入y。

 yum install mysql-server
 systemctl start mysqld

Harden MySQL Server

mysql_secure_installation

您将被选择更改MySQL根密码,删除匿名用户帐户,禁用本地主机以外的root登录名,并删除测试数据库。这些选项建议您回答yes。

使用MySQL

与MySQL交互的标准工具是mysql与mysql-server软件包一起安装的客户端。MySQL客户端通过终端使用。

root登录

1.以root用户身份登录MySQL:

mysql -u root -p

2.出现提示时,输入运行mysql_secure_installation脚本时分配的root密码。

然后,您将看到一个欢迎标题和MySQL提示符,如下所示:

mysql>

3.要生成MySQL提示符的命令列表,请输入\h。你会看到:

 List of all MySQL commands:
 Note that all text commands must be first on line and end with ';'
 ?         (\?) Synonym for `help'.
 clear     (\c) Clear command.
 connect   (\r) Reconnect to the server. Optional arguments are db and host.
 delimiter (\d) Set statement delimiter. NOTE: Takes the rest of the line as new delimiter.
 edit      (\e) Edit command with $EDITOR.
 ego       (\G) Send command to mysql server, display result vertically.
 exit      (\q) Exit mysql. Same as quit.
 go        (\g) Send command to mysql server.
 help      (\h) Display this help.
 nopager   (\n) Disable pager, print to stdout.
 notee     (\t) Don't write into outfile.
 pager     (\P) Set PAGER [to_pager]. Print the query results via PAGER.
 print     (\p) Print current command.
 prompt    (\R) Change your mysql prompt.
 quit      (\q) Quit mysql.
 rehash    (\#) Rebuild completion hash.
 source    (\.) Execute an SQL script file. Takes a file name as an argument.
 status    (\s) Get status information from the server.
 system    (\!) Execute a system shell command.
 tee       (\T) Set outfile [to_outfile]. Append everything into given outfile.
 use       (\u) Use another database. Takes database name as argument.
 charset   (\C) Switch to another charset. Might be needed for processing binlog with multi-byte charsets.
 warnings  (\W) Show warnings after every statement.
 nowarning (\w) Don't show warnings after every statement.
 For server side help, type 'help contents'
 mysql>

创建一个新的MySQL用户和数据库

1.在下面的例子中,testdb是数据库的名称,testuser是用户,password是用户的密码。

create database testdb;
 create user 'testuser'@'localhost' identified by 'password';
 grant all on testdb.* to 'testuser' identified by 'password';

2.退出mysql

exit

创建示例表

1.重新登录为testuser。

mysql -u testuser -p

2.创建一个名为customers的示例表。

use testdb;
create table customers (customer_id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, first_name TEXT, last_name TEXT);

3.退出mysql:

exit

重置MySQL的root密码

如果您忘记了MySQL的密码,可以重新设置。
停止当前的MySQL服务器实例,然后重新启动它,并选择不要求输入密码。

systemctl stop mysqld
mysqld_safe --skip-grant-tables &

2.使用MySQL根帐户重新连接到MySQL服务器。


mysql -u root

3.使用以下命令重置root的密码。替换password为你所需要的密码。

use mysql;
update user SET PASSWORD=PASSWORD("password") WHERE USER='root';
flush privileges;
exit

4.后重新启动MySQL。

systemctl start mysqld

翻译原文:https://www.linode.com/docs/databases/mysql/how-to-install-mysql-on-centos-7

www.htsjk.Com true http://www.htsjk.com/mariadb/35864.html NewsArticle centos7安装mysql,centos7mysql MySQL是用于Web和服务器应用程序的流行数据库管理系统。但是,MySQL不再在CentOS的存储库中,而且MariaDB已经成为提供的默认数据库系统。MariaDB被认为是MySQL的替...
相关文章
    暂无相关文章
评论暂时关闭