linux下Mysql 的安装、配置、数据导入导出
MySQL 是一种 开放源代码 的关系型 数据库管理 系统(RDBMS), 虽然功能未必很强大,但因它的免费开源而广受欢迎。 CSDN写日志总有问题,直接到这里看吧;http://www.cnblogs.com/alylee/p/MySql_Setup_Init.html 一、安装准备 下载得到安装包很简单。 1、rp
MySQL是一种开放源代码的关系型数据库管理系统(RDBMS),虽然功能未必很强大,但因它的免费开源而广受欢迎。
CSDN写日志总有问题,直接到这里看吧; http://www.cnblogs.com/alylee/p/MySql_Setup_Init.html
一、安装准备
下载得到安装包很简单。
1、rpm安装:A、在linux下使用wget获取 B、在虚拟机所在的宿主机windows下,在网络上下载Rpm安装包,然后通过之前我们配置的samba共享目录拷贝到centos下。
单独下载要注意你需要的rpm包:
MySQL-server-<span>5.1</span>.x-<span>0</span>.i386.rpm <span>//</span><span>服务端</span> MySQL-client-<span>5.1</span>.x-<span>0</span>.i386.rpm <span>//</span><span>客户端 </span> MySQL-devel-<span>5.1</span>.x-<span>0</span>.i386.rpm <span>//</span><span>开发包 ...</span>
2、yum 在线安装:使用CentOs的Yum(如果有特定的Mysql版本需求,要确定你的Yum库里有需要的mysql版本)
Yum (Yellow dog Updater, Modified)是一个基于rpm包管理的字符前端软件包管理器。能够从指定服务器自动下载rpm包并且安装,处理依赖性关系,并且一次安装所有依赖的软件包,无须繁琐地一次次下载、安装。 简单认识下几个操作: yum -y install samba #安装samba,“-y”接受所有,不用手动一个个去确认每一步。 yum remove samba #卸载samba yum info installed #列出系统中<span>所有安装过的</span>rpm包 yum list samba #列出资源库中<span>指定的</span>可以安装或更新以及已经安装的rpm包 yum info samba #列出资源库中<span>指定的</span>可以安装或更新以及已经安装的rpm包的信息 yum search samba #搜索匹配指定字符的rpm包
二、安装Mysql
检测当前系统是否已经安装了mysql :运行下面的命令,如果已经安装过,会显示mysql的版本信息。
rpm -qa|<span>grep</span> mysql
如果已经安装过mysql,但是不是自己需要的版本,比如需要高版本的mysql对事件的支持等,怎么办?删除呗!注意,这可能会删除一些相关的依赖库而影响到其他软件,不过可以重新安装。
<span>yum</span> remove mysql-server mysql-devel mysql-client #删除mysql的server、client、以及devel
1、rpm安装:
rpm -ivh MySQL-server-<span>5.1</span>.x-<span>0</span><span>.i386.rpm #安装服务端(x:你下载的对应版本号) rpm </span>-ivh MySQL-client-<span>5.1</span>.x-<span>0</span><span>.i386.rpm #安装客户端 rpm </span>-ivh MySQL-devel-<span>5.1</span>.x-<span>0</span>.i386.rpm #安装开发包
2、yum安装:
<span>yum</span> -y <span>install</span> mysql-<span>server #安装服务器端 </span><span>yum</span> -y <span>install</span> mysql-<span>client #安装客户端 </span><span>yum</span> -y <span>install</span> mysql-devel #安装开发包
这里注意:
A、根据你的开发环境需要,你可以选择对应的rpm包。你可以在命令行,使用"yum search mysql"搜索与mysql有关的安装包,从中选择你需要的。如果你记不住名字也可以这样搜索下。
<span>yum</span> search mysql
B、上面列出rpm包名字和简介,还可以通过yum info获取具体rpm包的具体的版本信息
<span>yum</span> <span>info</span> mysql-<span>server #列出mysql-server版本信息 </span><span>yum</span> <span>info</span> mysql-<span>client </span><span>yum</span> <span>info</span> mysql-<span>devel #或者 </span><span>yum</span> <span>info</span> mysql* #一个命令一下子列出mysql相关的所有rpm安装包版本信息
三、Mysql初始配置
刚刚安装好的mysql需要进行一定的配置,才适合使用。
1、设置Mysql开机启动
<span><span>chkconfig --list mysql #查看mysql服务开机启动状态</span> mysql 0:off1:off2:on3:on4:on5:on6:off </span>
<span><span>#如果2--5都是on,就不需要下面的命令了 chkconfig mysql on 设置mysql服务开机启动</span> </span>
chkconfig,如果不知道是干什么的,那现在来了解下
<span><span>chkconfig</span>,用来更新(启动或停止)和查询系统服务的运行级信息。 使用语法: chkconfig [</span>--add][--del][--list][系统服务] 或 chkconfig [--level ][系统服务][on/off/<span>reset]</span><span> eg: chkconfig </span>--<span>list [name]:显示所有运行级系统服务的运行状态信息(on或off)。如果指定了name,那么只显示指定的服务在不同运行级的状态。 chkconfig </span>--<span>add name:增加一项新的服务 chkconfig </span>--del name:删除服务<span> chkconfig [</span>--level levels] name:设置某一服务在指定的运行级是被启动,停止还是重置。 <span>level</span>,运行级别,可以用“runlevel”这个命令查询到当前系统的运行级别,也可以“init 0-6”切换运行级别
<span>0:表示关机 1:单用户模式 2:无网络连接的多用户命令行模式 3:有网络连接的多用户命令行模式 4:不可用 5:带图形界面的多用户模式 6:重新启动 </span>
2、Mysql服务的启动/关闭/重启
service mysql start/shutdown/restart/<span>status #启动、关闭、重启、查看服务当前状态 或者 </span>/etc/rc.d/init.d/mysqld start/shutdown/restart/status #启动、关闭、重启、查看服务当前状态
3、安全设置
<span>⑴、刚安装时,root用户是空的,需要修改密码: ①mysqladmin </span><span>-</span>u>password(<span>'</span><span>123456</span><span>'</span><span>); #设置指定域名下root账号的密码 </span><span>set</span>>password(<span>'</span><span>123456</span><span>'</span><span>); </span><span><strong>3</strong></span><span>.或者,更常见的sql操作: </span><span>update</span> <span>user</span> <span>set</span>>password(<span>'</span><span>123456</span><span>'</span>) <span>where</span> <span>user</span><span>=</span>‘root<span>@localhost</span><span>’; ⑵、匿名用户是危险的 </span><span>delete</span> <span>from</span>><span>''</span>; #删除匿名用户 ⑶、退出mysql: <span>exit</span>;
4、测试
登陆:
<span>[</span><span>root@dream ~</span><span>]</span>mysql <span>-</span><span>u root #匿名登录,已设置密码或者删除了匿名用户,登陆失败 </span><span>[</span><span>root@dream ~</span><span>]</span>mysql <span>-</span>u root <span>-</span><span>p #通过密码用root登录 Enter password: #在这里输入密码123456 </span><span>[</span><span>root@dream ~</span><span>]</span>mysql <span>-</span>u root <span>-</span>p <span><strong>123456</strong></span> #显示密码登陆
sql操作:
mysql<span>></span> <span>create</span> <span>database</span><span> test; #建立名为test的数据库,这个库安装后就有的。 mysql</span><span>></span><span> show databases; #查看系统已存在的数据库 mysql</span><span>></span> <span>use</span><span> test #切换到指定的数据库 mysql</span><span>></span> <span>create</span> <span>table</span> tbl_user(ID <span>int</span>, Name <span>varchar</span>(<span><strong>50</strong></span><span>)); #建立表 mysql</span><span>></span><span> show tables; #查看数据库中已存在的表 mysql</span><span>></span> <span>drop</span> <span>table</span><span> tbl_user; #删除表 mysql</span><span>></span><span>drop</span> <span>database</span><span> test; #删除名为test数据库 mysql</span><span>></span> <span>exit</span> #退出MySQL服务器
5、NaviCat远程连接的权限问题
远程登录会出现如下提示:
<span><strong>1103</strong></span> <span>-</span> host xxx.xxx.xxx.xx <span>is</span> <span>not</span> allowed <span>to</span> connec <span>to</span><span> this mysql server. 或 </span><span><strong>1045</strong></span> <span>-</span> Access denied <span>for</span> <span>user</span> <span>'</span><span>root</span><span>'</span>@<span>'</span><span>192.168.1.11</span><span>'</span> (using password: YES).
解决方案:
<span>//</span><span>mysql访问 </span><span>grant</span> <span>all</span> <span>privileges</span> <span>on</span> <span>*</span>.<span>*</span> <span>to</span> <span>'</span><span>root</span><span>'</span>@<span>'</span><span>%</span><span>'</span> identified <span>by</span> <span>'</span><span>123456</span><span>'</span><span>; #其实就是权限问题,设置root在所有域名(</span>%<span>表示任何地址</span>)登陆时,赋给所有权限,密码123456。根据需要可设置更严格些。
四、数据库和表的导入、导出
1.导出整个的数据库:mysqldump -u 用户名 -p 数据库名 > 导出的文件名
mysqldump -u root -p db_test >/home/bak/dbtest.sql
2.导出指定数据库中的一个表:mysqldump -u 用户名 -p 数据库名 表名> 导出的文件名
mysqldump -u root -p db_test tbl_user >/home/bak/test_user.sql
3.只导出一个结构(struct):加上-d参数
mysqldump -u root -p -d –add-drop-table db_test >/home/bak/dbtest_struct.sql
4.只导出一个数据(data):加上-t参数
mysqldump -u root -p -t –add-drop-table db_test >/home/bak/dbtest_struct.sql
<span>⑴.只导出表结构 -d mysqldump </span><span>-</span>h 192.<span><strong>168.1</strong></span>.<span><strong>11</strong></span> <span>-</span>u>utf8 test <span>></span><span>sql.sql ⑵.只导出数据 -t mysqldump </span><span>-</span>h 192.<span><strong>168.1</strong></span>.<span><strong>11</strong></span> <span>-</span>u>utf8 test <span>></span>sql.sql 注:①.<span>-d</span> 没有数据(不导出数据,只导出数据结构和表结构)
-t 不导出结构,只要数据
–add-drop-table 在每个create语句之前增加一个drop table
–default-character-set 设置字符集
②.这里的导出文件没有加路径,就是相对路径,当前的目录下的文件。
③.密码是显示输入的,跟在-p后面。
5.导入数据库:source 命令
<span>[</span><span>root@dream ~</span><span>]</span> mysql <span>-</span>u root <span>-</span><span>p #登陆 mysql</span><span>></span><span>use</span><span> test; mysql</span><span>></span>source <span>/</span>home<span>/</span>bak<span>/</span>db_test.sql
!
作者:子韦一

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

DeepSeek is a powerful intelligent search and analysis tool that provides two access methods: web version and official website. The web version is convenient and efficient, and can be used without installation; the official website provides comprehensive product information, download resources and support services. Whether individuals or corporate users, they can easily obtain and analyze massive data through DeepSeek to improve work efficiency, assist decision-making and promote innovation.

One of the major changes introduced in MySQL 8.4 (the latest LTS release as of 2024) is that the "MySQL Native Password" plugin is no longer enabled by default. Further, MySQL 9.0 removes this plugin completely. This change affects PHP and other app

There are many ways to install DeepSeek, including: compile from source (for experienced developers) using precompiled packages (for Windows users) using Docker containers (for most convenient, no need to worry about compatibility) No matter which method you choose, Please read the official documents carefully and prepare them fully to avoid unnecessary trouble.

BITGet is a cryptocurrency exchange that provides a variety of trading services including spot trading, contract trading and derivatives. Founded in 2018, the exchange is headquartered in Singapore and is committed to providing users with a safe and reliable trading platform. BITGet offers a variety of trading pairs, including BTC/USDT, ETH/USDT and XRP/USDT. Additionally, the exchange has a reputation for security and liquidity and offers a variety of features such as premium order types, leveraged trading and 24/7 customer support.

Ouyi OKX, the world's leading digital asset exchange, has now launched an official installation package to provide a safe and convenient trading experience. The OKX installation package of Ouyi does not need to be accessed through a browser. It can directly install independent applications on the device, creating a stable and efficient trading platform for users. The installation process is simple and easy to understand. Users only need to download the latest version of the installation package and follow the prompts to complete the installation step by step.

Gate.io is a popular cryptocurrency exchange that users can use by downloading its installation package and installing it on their devices. The steps to obtain the installation package are as follows: Visit the official website of Gate.io, click "Download", select the corresponding operating system (Windows, Mac or Linux), and download the installation package to your computer. It is recommended to temporarily disable antivirus software or firewall during installation to ensure smooth installation. After completion, the user needs to create a Gate.io account to start using it.

Ouyi, also known as OKX, is a world-leading cryptocurrency trading platform. The article provides a download portal for Ouyi's official installation package, which facilitates users to install Ouyi client on different devices. This installation package supports Windows, Mac, Android and iOS systems. Users can choose the corresponding version to download according to their device type. After the installation is completed, users can register or log in to the Ouyi account, start trading cryptocurrencies and enjoy other services provided by the platform.

Gate.io is a highly acclaimed cryptocurrency trading platform known for its extensive token selection, low transaction fees and a user-friendly interface. With its advanced security features and excellent customer service, Gate.io provides traders with a reliable and convenient cryptocurrency trading environment. If you want to join Gate.io, please click the link provided to download the official registration installation package to start your cryptocurrency trading journey.
