centos怎么安装mysql
发布网友
发布时间:2022-02-26 19:21
我来回答
共2个回答
懂视网
时间:2022-02-26 23:42
产品型号:Thinkpad E15
系统版本:centos7
软件版本:mysql 5.7
mysql安装教程
1.使用yum安装mysql数据库的软件包
[root@xuegod63 ~]# yum -y install mariadb-server mariadb
注:
mariadb-server #MariaDB数据库
mariadb # MariaDB服务器Linux下客户端
注:从centos7系统开始,系统中自带的mysql数据库变成了mariadb-server,mariadb-server和mysql操作上一样。mariadb-server是mysql的一个分支。
2.启动数据库服务
[root@xuegod63 ~]# systemctl start mariadb #启动MariaDB服务
[root@xuegod63 ~]# systemctl enable mariadb #设置开启自动启动MariaDB服务
3. 安装完mariadb-server后,运行mysql_secure_installation去除安全隐患
[root@xuegod63 ~]# mysql_secure_installation #进入安全配置导向
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
In order to log into MySQL to secure it, we'll need the current
password for the root user. If you've just installed MySQL, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.
Enter current password for root (enter for none): #初次运行直接回车,因为root用户没有密码
OK, successfully used password, moving on…
Setting the root password ensures that nobody can log into the MySQL
root user without the proper authorisation.
Set root password? [Y/n] Y #是否设置root用户密码,输入Y
New password: 123456 #新密码123456
Re-enter new password: 123456
Password updated successfully!
。。。
Remove anonymous users? [Y/n] Y #是否删除匿名用户,生产环境建议删除,所以直接回车或Y
... Success!
Normally, root should only be allowed to connect from 'localhost'. This
ensures that someone cannot guess at the root password from the network.
Disallow root login remotely? [Y/n] Y #是否禁止root远程登录,根据自己的需求选择Y/n并回车,建议禁止
... Success!
By default, MariaDB comes with a database named 'test' that anyone can
access. This is also intended only for testing, and should be removed
before moving into a production environment.
Remove test database and access to it? [Y/n] Y #是否删除test数据库,直接回车或Y
- Dropping test database...
... Success!
- Removing privileges on test database...
... Success!
Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.
Reload privilege tables now? [Y/n] Y #是否重新加载权限表,直接回车
... Success!
Cleaning up...
All done! If you've completed all of the above steps, your MariaDB
installation should now be secure.
Thanks for using MariaDB!
… Success!
至此数据库安装成功。
4. 登录数据库
[root@xuegod63 ~]# mysql -u root -p123456
MariaDB [(none)]> show databases; #没有test数据库 #执行时,所有命令以;号结尾
+-------------------------+
| Database |
+-------------------------+
| information_schema |
| mysql |
| ucenter |
+-------------------------+
3 rows in set (0.00 sec)
MariaDB [(none)]> exit #退出命令可以加分号,也可以不加分号。
总结:
1、使用yum安装mysql数据库的软件包
2、启动数据库服务
3、运行mysql_secure_installation去除安全隐患
4、登录数据库
热心网友
时间:2022-02-26 20:50
当前位置: > CentOS服务器 > 数据库服务器 > MySQL >
centos6.5下安装mysql
时间:2014-08-12 01:11来源:blog.csdn.net 作者:brushli 举报 点击:17509次
1.使用yum命令安装mysql
[html] view plaincopy
[root@bogon ~]# yum -y install mysql-server
2.设置开机启动
[html] view plaincopy
[root@bogon ~]# chkconfig mysqld on
3.启动MySQL服务
[html] view plaincopy
[root@bogon ~]# service mysqld start
4.设置MySQL的root用户设置密码
[html] view plaincopy
[root@bogon ~]# mysql -u root
mysql> select user,host,password from mysql.user;
+------+-----------+----------+
| user | host | password |
+------+-----------+----------+
| root | localhost | |
| root | bogon | |
| root | 127.0.0.1 | |
| | localhost | |
| | bogon | |
+------+-----------+----------+
5 rows in set (0.01 sec)
查询用户的密码,都为空,用下面的命令设置root的密码为root
[html] view plaincopy
mysql> set password for root@localhost=password('root');
mysql> exit
5.用新密码登陆
[html] view plaincopy
[root@bogon ~]# mysql -u root -p
Enter password:
6.创建mysql新用户test_user
[html] view plaincopy
mysql> create user 'test_user'@'%' identified by 'test_user';
Query OK, 0 rows affected (0.00 sec)
7.给新用户test_user授权,让他可以从外部登陆和本地登陆
注意:@左边是用户名,右边是域名、IP和%,表示可以访问mysql的域名和IP,%表示外部任何地址都能访问。
[html] view plaincopy
mysql> grant all privileges on *.* to 'test_user'@'localhost' identified by 'test_user';
Query OK, 0 rows affected (0.00 sec)
mysql> grant all privileges on *.* to 'test_user'@'%' identified by 'test_user';
Query OK, 0 rows affected (0.00 sec)
mysql> select user,host,password from mysql.user;
+----------+-----------+-------------------------------------------+
| user | host | password |
+----------+-----------+-------------------------------------------+
| root | localhost | *81F5E21E35407D884A6CD4A731AEBFB6AF209E1B |
| root | bogon | |
| root | 127.0.0.1 | |
| | localhost | |
| | bogon | |
| test_user | % | *3046CF87132BBD4FDDF06F321C6859074843B7D3 |
| test_user | localhost | *3046CF87132BBD4FDDF06F321C6859074843B7D3 |
+----------+-----------+-------------------------------------------+
7 rows in set (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)
8.查看mysql5.1的默认存储引擎
从下面的执行结果可以看出,mysql的默认引擎是MyISAM,这个引擎是不支持事务的。
[html] view plaincopy
mysql> show engines;
+------------+---------+------------------------------------------------------------+--------------+------+------------+
| Engine | Support | Comment | Transactions | XA | Savepoints |
+------------+---------+------------------------------------------------------------+--------------+------+------------+
| MRG_MYISAM | YES | Collection of identical MyISAM tables | NO | NO | NO |
| CSV | YES | CSV storage engine | NO | NO | NO |
| MyISAM | DEFAULT | Default engine as of MySQL 3.23 with great performance | NO | NO | NO |
| InnoDB | YES | Supports transactions, row-level locking, and foreign keys | YES | YES | YES |
| MEMORY | YES | Hash based, stored in memory, useful for temporary tables | NO | NO | NO |
+------------+---------+------------------------------------------------------------+--------------+------+------------+
5 rows in set (0.00 sec)
也可以以下面的方式查看
[html] view plaincopy
mysql> show variables like 'storage_engine';
+----------------+--------+
| Variable_name | Value |
+----------------+--------+
| storage_engine | MyISAM |
+----------------+--------+
1 row in set (0.00 sec)
9.修改mysql的默认引擎为InnoDB
9.1 停止mysql
[html] view plaincopy
mysql> exit;
[root@bogon ~]# service mysqld stop
9.2 修改/etc/my.cnf
[mysqld] 后加入
[html] view plaincopy
default-storage-engine=InnoDB
加入后my.cnf的内容为:
[html] view plaincopy
[root@bogon etc]# more my.cnf
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
default-storage-engine=InnoDB
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
9.3 启动mysql
[html] view plaincopy
[root@bogon etc]# service mysqld start
Starting mysqld: [ OK ]
9.4 查看mysql默认存储引擎
[html] view plaincopy
[root@bogon etc]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.1.73 Source distribution
Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> show variables like 'storage_engine';
+----------------+--------+
| Variable_name | Value |
+----------------+--------+
| storage_engine | InnoDB |
+----------------+--------+
1 row in set (0.00 sec)
10.CentOS6.5开放mysql端口3306
CentOS6.5默认是不开放端口的,如果要让外部的系统访问CentOS6.5上的mysql,必须开放mysql的端口3306
10.1 修改/etc/sysconfig/iptables
添加下面一行
[html] view plaincopy
-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT
修改后iptables中的内容是
[html] view plaincopy
[root@bogon etc]# more /etc/sysconfig/iptables
# Firewall configuration written by system-config-firewall
# Manual customization of this file is not recommended.
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
#添加配置项
-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 11211 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
COMMIT
11.重启防火墙
[html] view plaincopy
[root@bogon etc]# service iptables restart
这样就可以从外部访问mysql了。
至此,mysql在CentOS6.5上的安装过程、用户创建、外部访问的步骤全部完成。
在CentOS上安装MySQL的详细步骤和相关命令
在CentOS系统中安装MySQL的详细指导如下:首先,确保你的系统是最新的状态,以保证安装过程的顺利进行:接下来,为安装过程准备必要的依赖库,这将为MySQL的编译和运行提供支持:若安装特定版本(如8.0)的MySQL,可能需要添加相应的官方或第三方Yum仓库。以官方仓库为例,添加步骤如下:然后,使用Yum工具安...
还在找storm proxy?
作为上海圣钧信息科技有限公司的工作人员,我公司并不提供名为"Storm Proxy"的服务。我们致力于提供高质量的信息技术服务,包括但不限于云计算、大数据处理、人工智能等领域。我们的服务对象主要是企业客户,为其提供定制化的解决方案和技术支持。如果您正在寻找相关的服务,建议您通过搜索引擎或行业专业网站等途径进行查询。同时,请注意防范虚假信息和欺诈行为,确保您选择正规、可靠的服务提供商。如有其他问题或需要进一步了解,欢迎随时与我们联系。SmartProxy企业级海外住宅IP代理服务商,覆盖全球200+国家和地区,高匿稳定,动态住宅代理/静态住宅代理/账密提取,100%原生住宅IP,城市级定位,支持HTTP/HTTPS/SOCKS5协议,不限带宽,纯净高匿,网络集成更快捷,注册即送流量!Smartproxy代理...
CentOS7安装MySQL数据库的指南cent7安装mysql
`sudo systemctl start mysqld`MySQL服务现在可以正常运行。安全设置 安装MySQL后,建议立即进行安全设置以确保数据的安全性。MySQL提供了一个名为mysql_secure_installation的脚本,可以自动完成这项任务。在CentOS7终端中输入以下命令即可使用:`sudo mysql_secure_installation`该脚本将依次提示您输入root用户...
如何在CentOS下安装mysql
方法/步骤 首先,需要有一个centos系统,不管是虚拟机还是直接在电脑上安装。下图就是进入到centos系统下的截图。(界面不比windows差哦)之后,是进入到类始于windows下的控制台页面(如果你是安装的虚拟机那你可以通过putty等工具,直接在windows下类似于远程访问,进入到控制台下)之后,进入到控制台下,...
linux(Centos7.4)下安装mysql8.0.26离线安装教程图解
`rpm -ivh mysql-community-client-8.0.26-1.el7.x86_64.rpm`完成安装后,启动MySQL服务,使用命令`systemctl status mysqld`检查服务状态。若需要停止服务,则执行`service mysqld stop`。初始化数据库时,确保没有/var/lib/mysql目录,若存在需删除,执行`rm -rf /var/lib/mysql`。执行`mysql...
CentOS7.6安装MySQL(rpm安装)
安装MySQL使用rpm来安装MySQL 因为CentOS7默认安装的数据库是Mariadb,所以使用YUM命令是无法安装MySQL的,只会更新Mariadb。使用rpm来进行安装。可以在mysql的repo源仓库右键复制指定版本的数据库。wgethttp://repo.mysql.com/mysql80-community-release-el7-1.noarch.rpm 安装mysql80-community-release-el7-...
如何安装 MySQL 客户端 - Mac, Ubuntu, CentOS 或 Windows
进行验证。CentOS用户安装MySQL客户端的命令为 sudo yum install mysql-client 完成安装后,使用命令 mysql --version 进行验证。对于Windows用户,安装好MySQL客户端后,使用命令测试客户端与MySQL服务器的连接 mysql -h hostname -u username -p 了解更多MySQL工具,可以访问官网,注册云账号,体验Bytebase...
CentOS7上面安装MySQL8(非yum安装)
在CentOS7上安装MySQL8的步骤并不复杂,首先从MySQL官网下载对应版本。选择8.0.37,操作系统为Linux-Generic,根据你的Linux系统版本(如glibc 2.17,注意可能是32或64位)选择相应的选项。下载时,使用浏览器的开发者工具获取下载链接,选择合适的包并复制URL。接下来,登录Linux系统,进入你计划安装MySQL...
centos安装mysql数据库的方法
1、首先下载MySQL的安装文件,我这里安装的是MySQL5.1.7版本的,2、安装MySQL数据库服务器进入安装包所在文件夹,执行命令 rpm -ivh MySQL-server-5.1.7-0.i386.rpm 安装MySQL服务器。如果报了与原先版本冲突的话,就执行rpm -qa|grep -i mysql命令,会显示已安装的Mysql版本,我的显示mysql-libs-5.1.61-4.el6....
CentOS Linux 7离线安装MySQL 5.7.21(亲测)
在 CentOS 上进行 MySQL 5.7.21 的离线安装可以遵循以下步骤,确保系统的稳定性和兼容性。首先,需要禁用 SELinux 服务以避免安装过程中出现的阻止行为。同时,为了防止误操作导致的系统问题,切勿卸载 CentOS 自带的 mariadb 数据库。在安装 MySQL 时,系统会自动替换 mariadb,自行卸载会引发后续问题。
centos stream 9 安装 mysql8
如果你的物理主机为ARM架构的Mac,且需要在ARM架构的Linux(比如CentOS Stream 9)上安装MySQL 8.4.0,那么选择对应的ARM架构版本(mysql-8.4.0-linux-glibc2.28-aarch64)是关键步骤。首先,确认系统上是否已预装数据库,如果没有,你将从下载的安装包开始。将mysql-8.4.0-linux-glibc2.28-a...