阿里云的CentOS环境中安装配置MySQL的教程

来源:互联网 发布:mysql group by 索引 编辑:程序博客网 时间:2024/06/05 00:54

http://www.jb51.net/article/76493.htm

众所周知,Linux系统自带的repo是不会自动更新每个软件的最新版本(基本都是比较靠后的稳定版),所以无法通过yum方式安装MySQL的高级版本。所以我们需要先安装带有当前可用的mysql5系列社区版资源的rpm包。

#######安装rpm包[root@typecodes ~]# rpm -Uvh http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm
Retrieving http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpmPreparing...       ################################# [100%]Updating / installing... 1:mysql-community-release-el7-5 ################################# [100%]
这时查看当前可用的mysql安装资源:
[root@typecodes ~]# yum repolist enabled | grep "mysql.*-community.*"mysql-connectors-community/x86_64 MySQL Connectors Community     14mysql-tools-community/x86_64  MySQL Tools Community      17mysql56-community/x86_64   MySQL 5.6 Community Server    139

从上面的列表可以看出, mysql56-community/x86_64 和 MySQL 5.6 Community Server 可以使用。

因此,我们就可以直接用yum方式安装了MySQL5.6版本了。

[root@typecodes ~]# yum -y install mysql-community-server
安装完MySQL后,需要进行一些基础配置工作:

#######安装成功后,将其加入开机启动[root@typecodes ~]# systemctl enable mysqld #######启动mysql服务进程[root@typecodes ~]# systemctl start mysqld #######配置mysql(设置密码等)[root@typecodes ~]# mysql_secure_installation
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL  SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY! 这里需要注意的是,如果你是新安装的mysql,会弹出如下提示:In order to log into MySQL to secure it, we'll need the currentpassword for the root user. If you've just installed MySQL, andyou haven't set the root password yet, the password will be blank,so you should just press enter here. 大概意思就是如果你是新安装的话,你的默认密码是空,直接按enter键就可以了Enter current password for root (enter for none): OK, successfully used password, moving on... 然后设置新的密码,输入两次。再然后,会有若干个提示:Setting the root password ensures that nobody can log into the MySQLroot user without the proper authorisation.Set root password? [Y/n] y     [设置root用户密码]New password: Re-enter new password: Password updated successfully!Reloading privilege tables.. ... Success!  By default, a MySQL installation has an anonymous user, allowing anyoneto log into MySQL without having to have a user account created forthem. This is intended only for testing, and to make the installationgo a bit smoother. You should remove them before moving into aproduction environment. 大概意思是,mysql会默认创建一个匿名用户,方便你测试什么的,现在问你要不要删掉它,果断删掉Remove anonymous users? [Y/n] y     [删除匿名用户] ... Success! Normally, root should only be allowed to connect from 'localhost'. Thisensures that someone cannot guess at the root password from the network. 大概意思是,root用户默认只能访问localhost,以防止有人猜你的密码。。。问你是否禁止root登陆,也选yes,虽然基本上不会有人来猜吧。Disallow root login remotely? [Y/n] y  [禁止root远程登录] ... Success! By default, MySQL comes with a database named 'test' that anyone canaccess. This is also intended only for testing, and should be removedbefore moving into a production environment. 大概意思是,mysql默认创建了一个名为test的数据库,这个库任何人都可以访问,问你是不是要把它删掉,也删掉。Remove test database and access to it? [Y/n] y   [删除test数据库] - Dropping test database...ERROR 1008 (HY000) at line 1: Can't drop database 'test'; database doesn't exist ... Failed! Not critical, keep moving... - Removing privileges on test database... ... Success! Reloading the privilege tables will ensure that all changes made so farwill take effect immediately. 大概意思是,上面所有的修改是否马上生效,选yReload privilege tables now? [Y/n] y   [刷新权限] ... Success!    All done! If you've completed all of the above steps, your MySQLinstallation should now be secure. Thanks for using MySQL!  Cleaning up...

skip-name-resolveskip-external-lockingkey_buffer_size = 256M#table_cache = 3072table_open_cache = 3072read_buffer_size = 2Mread_rnd_buffer_size = 2Msort_buffer_size = 2Mmyisam_sort_buffer_size = 256Mthread_cache_size = 8query_cache_size= 512Mquery_cache_limit= 5Mtmp_table_size=1024Mmax_heap_table_size=3000Mmax_allowed_packet = 16Minnodb_buffer_pool_size = 512Minnodb_log_file_size = 512Minnodb_additional_mem_pool_size=512Minnodb_log_buffer_size=64Mmax_connections=2000max_user_connections=800join_buffer_size = 8Mopen_files_limit = 65535#tmpdir=/dev/shmmax_connect_errors=1000

/usr/bin/mysql -uroot -p

#输入密码连接数据库

show databases;#查看数据库

use test;#使用某个数据库

show tables;#查看所有数据表







0 0