国语自产精品视频在线看:您身边最放心的安全下载站! 最新软件|热门排行|软件分类|软件专题|厂商大全

国语自产精品视频在线看

技术教程
您的位置:首页数据库类MySQL → ubuntu 13.04 安装mysql数据库教程

ubuntu 13.04 安装mysql数据库教程

我要评论 2013/11/30 15:19:12 来源:国语自产精品视频在线看 编辑:zbbingyang.com [ ] 评论:0 点击:387次

Ubuntu是一个流行的Linux操作系统,基于Debian发行版和GNOME桌面环境,和其他Linux发行版相比,Ubuntu非常易用,和Windows相容性很好,非常适合Windows用户的迁移,预装了大量常用软件,中文版的功能也较全,支持拼音输入法,预装了firefox、Open Office、多媒体播放、图像处理等大多数常用软件,一般会自动安装网卡、音效卡等设备的驱动。

安装MySQL

在【zài】Ubuntu上可以📈使用🦄Ubuntu Software Center或者apt命令来🕹安装MySQL,两种方【liǎng zhǒng fāng】式都十分方便【fèn fāng biàn】。

1. 使用😿Ubuntu Software Center:打开【dǎ kāi】🤼Ubuntu Software Center,在右上角的搜索框查询mysql,然后选🌎定MySQL Server,点击安【diǎn jī ān】装即可【zhuāng jí kě】。

2. 使用【shǐ yòng】🀄apt:打开终【dǎ kāi zhōng】端执行 ”sudo apt-get install mysql-server“ 即可🔜。

MySQL初始配置

MySQL完成安装后可以直接🚘使用【shǐ yòng】root账户登【zhàng hù dēng】🧐录,且该账户【zhàng hù】🤷默认是【mò rèn shì】没有密码的【de】🌩。注意这里的【lǐ de】🌩root角色就是指你【shì zhǐ nǐ】的【de】🌩Ubuntu的【de】🌩root角色,如【rú】果你当前使🐭用的系【yòng de xì】☕统帐号不是🛥root的【de】🌩话【huà】,也不必切换到系统【xì tǒng】🧗root账户【zhàng hù】🤷,可以在😐登录MySQL的【de】时候🛫使用【shǐ yòng】“-u"这个参数来指定登录账户【zhàng hù】🤷。如【rú】:

$ mysql -u root mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | test | +--------------------+ 4 rows in set (0.00 sec) mysql> select Host, User from user; +-----------+------------------+ | Host | User | +-----------+------------------+ | 127.0.0.1 | root | | ::1 | root | | iUbuntu | | | iUbuntu | root | | localhost | | | localhost | debian-sys-maint | | localhost | root | +-----------+------------------+ 7 rows in set (0.00 sec)

因为此【yīn wéi cǐ】💋时🐦root账户默【zhàng hù mò】认没有密码,所以不用输入【yòng shū rù】🚗密码就能以🚣root角色登录👽并查看【bìng chá kàn】所有信【suǒ yǒu xìn】息的🐞权限【xiàn】。如果换【rú guǒ huàn】成非root角色登录👽MySQL,则只拥有部分数据库💩操作权【cāo zuò quán】限【xiàn】。

$ mysql mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | test | +--------------------+ 2 rows in set (0.00 sec) mysql> use mysql ERROR 1044 (42000): Access denied for user ''@'localhost' to database 'mysql'

因此【yīn cǐ】🚅MySQL完成安装后的🎖第一件【dì yī jiàn】事就是给root用户设置密码🏆,否则数据库将【jù kù jiāng】毫无安【háo wú ān】🏯全可言。

mysql> GRANT ALL PRIVILEGES ON *.* TO root@localhost IDENTIFIED BY "<password>";

将以【yǐ】上🥈命令中的<password>替换为【tì huàn wéi】你要设定的密码【mǎ】,以【yǐ】上命📷令的意思是对在本机(localhost)使用<password>密码【mǎ】登🤣录的【lù de】root用户赋👄予所有数据库🌇的操作🌌权限【quán xiàn】。设置密码【mǎ】后💃,如果再以【yǐ】root用户登【yòng hù dēng】🚡录就需【lù jiù xū】要输入【yào shū rù】密码了【mì mǎ le】📿,如:

$ mysql -u root ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO) $ mysql -u root -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 75 Server version: 5.5.34-0ubuntu0.13.10.1 (Ubuntu) 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>

建立数📡据库独【jù kù dú】立用户

因为【yīn wéi】root用户拥有数据【yǒu shù jù】库【kù】🦂的所有操作📉权限,所以不【suǒ yǐ bú】能轻易地提供【dì tí gòng】📙给别人使用。在一个MySQL实例中【shí lì zhōng】可以创建多个🐷数据库【jù kù】🦂,这些数【zhè xiē shù】据库【jù kù】🦂可能归属🥗于不同项目🏟,每个数【měi gè shù】🕙据库【jù kù】的操作角色也不❣一样。对此可以针对不同那个数据【gè shù jù】库【kù】🦂指定用户进行访问【fǎng wèn】🏬。

首先使【shǒu xiān shǐ】🐴用【yòng】root角色创建一个【jiàn yī gè】数据库🐩 mysql> create database db_web_monitor 然后将这个数据库🐩授予一个🤣叫【jiào】xavier的用户【yòng hù】✝使用【shǐ yòng】 mysql> GRANT ALL PRIVILEGES ON db_web_monitor.* TO xavier@localhost IDENTIFIED BY "xavier";

这样就🏳可以使用【shǐ yòng】xavier用户【yòng hù】✝,密码为xavier在本机【zài běn jī】登录MySQL操作🙃db_web_monitor数据库🐩了🌰。

$ mysql -u xavier ERROR 1045 (28000): Access denied for user 'xavier'@'localhost' (using password: NO) $ mysql -u xavier -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 77 Server version: 5.5.34-0ubuntu0.13.10.1 (Ubuntu) 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 databases; +--------------------+ | Database | +--------------------+ | information_schema | | db_web_monitor | | test | +--------------------+ 3 rows in set (0.00 sec) mysql>

开放远程登录【chéng dēng lù】权限🎐

1. 首先修改🔜MySQL的配置【de pèi zhì】🚬文件,允许监【yǔn xǔ jiān】听远程🕝登录【dēng lù】。

$ sudo vi /etc/mysql/my.cnf 找到🌱bind-address所在行 45 # Instead of skip-networking the default is now to listen only on 46 # localhost which is more compatible and is not less secure. 47 bind-address = 127.0.0.1 将【jiāng】 bind-address值修改为本机IP即可【jí kě】🐋。 注意注❤释说明,如果是较老版本的MySQL,此处就应该是【yīng gāi shì】skip-networking,直接将【jiāng】其注释🏝即可【jí kě】🐋。

2. 授予用【shòu yǔ yòng】户远程登录权⛺限【xiàn】🦅。

mysql>GRANT ALL PRIVILEGES ON db_web_monitor.* TO xavier@"%" IDENTIFIED BY "xavier";

如此这【rú cǐ zhè】般🕰,xavier用户就可以在任意主🦀机通过【jī tōng guò】🧐IP访问到【fǎng wèn dào】本机👐MySQL,对db_web_monitor数据库进行操作了【zuò le】。

关键词【guān jiàn cí】:ubuntu,mysql,数据库🔪

阅读本文后您有什么感想? 已有 人给出评价!

  • 1 欢迎喜欢
  • 1 白痴
  • 1 拜托
  • 1 哇
  • 1 加油
  • 1 鄙视