1.检测系统是否自带安装mysql
# yum list installed | grep mysql
2.如果发现有系统自带mysql,删除
# yum -y remove mysql-libs.x86_64
3.随便在你存放文件的目录下执行,mysql5.6只有79M大,
# wget http://repo.mysql.com/mysql-community-release-el6-5.noarch.rpm
[root@localhost local]# wget http://repo.mysql.com/mysql-community-release-el6-5.noarch.rpm
--2018-08-23 13:12:27-- http://repo.mysql.com/mysql-community-release-el6-5.noarch.rpm
Resolving repo.mysql.com... 2.21.22.184
Connecting to repo.mysql.com|2.21.22.184|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 5824 (5.7K) [application/x-redhat-package-manager]
Saving to: “mysql-community-release-el6-5.noarch.rpm”
100%[======================================>] 5,824 --.-K/s in 0s
2018-08-23 13:12:27 (930 MB/s) - “mysql-community-release-el6-5.noarch.rpm” saved [5824/5824]
4.接着执行这句,解释一下,这个rpm还不是mysql的安装文件,只是两个yum源文件
# rpm -ivh mysql-community-release-el6-5.noarch.rpm
Preparing... ########################################### [100%]
1:mysql-community-release########################################### [100%]
5.用yum repolist mysql这个命令查看一下是否已经有mysql可安装文件
#yum repolist all | grep mysql
mysql-connectors-community MySQL Connectors Community enabled: 59
mysql-connectors-community-source MySQL Connectors Community - So disabled
mysql-tools-community MySQL Tools Community enabled: 65
mysql-tools-community-source MySQL Tools Community - Source disabled
mysql55-community MySQL 5.5 Community Server disabled
mysql55-community-source MySQL 5.5 Community Server - So disabled
mysql56-community MySQL 5.6 Community Server enabled: 453
mysql56-community-source MySQL 5.6 Community Server - So disabled
mysql57-community-dmr MySQL 5.7 Community Server Deve disabled
mysql57-community-dmr-source MySQL 5.7 Community Server Deve disabled
6.安装mysql 服务器命令(一路yes):
# yum install mysql-community-server
Loaded plugins: fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.cn99.com
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package mysql-community-server.x86_64 0:5.6.41-2.el6 will be installed
--> Processing Dependency: mysql-community-common(x86-64) = 5.6.41-2.el6 for package: mysql-community-server-5.6.41-2.el6.x86_64
--> Processing Dependency: mysql-community-client(x86-64) >= 5.6.10 for package: mysql-community-server-5.6.41-2.el6.x86_64
--> Processing Dependency: perl(DBI) for package: mysql-community-server-5.6.41-2.el6.x86_64
--> Running transaction check
---> Package mysql-community-client.x86_64 0:5.6.41-2.el6 will be installed
--> Processing Dependency: mysql-community-libs(x86-64) >= 5.6.10 for package: mysql-community-client-5.6.41-2.el6.x86_64
---> Package mysql-community-common.x86_64 0:5.6.41-2.el6 will be installed
---> Package perl-DBI.x86_64 0:1.609-4.el6 will be installed
--> Running transaction check
---> Package mysql-community-libs.x86_64 0:5.6.41-2.el6 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
================================================================================
Package Arch Version Repository Size
================================================================================
Installing:
mysql-community-server x86_64 5.6.41-2.el6 mysql56-community 55 M
Installing for dependencies:
mysql-community-client x86_64 5.6.41-2.el6 mysql56-community 18 M
mysql-community-common x86_64 5.6.41-2.el6 mysql56-community 308 k
mysql-community-libs x86_64 5.6.41-2.el6 mysql56-community 1.9 M
perl-DBI x86_64 1.609-4.el6 base 705 k
Transaction Summary
================================================================================
Install 5 Package(s)
Total download size: 75 M
Installed size: 337 M
Is this ok [y/N]: y
Downloading Packages:
(1/5): mysql-community-client-5.6.41-2.el6.x86_64.rpm | 18 MB 00:03
(2/5): mysql-community-common-5.6.41-2.el6.x86_64.rpm | 308 kB 00:00
(3/5): mysql-community-libs-5.6.41-2.el6.x86_64.rpm | 1.9 MB 00:00
(4/5): mysql-community-server-5.6.41-2.el6.x86_64.rpm | 55 MB 00:08
(5/5): perl-DBI-1.609-4.el6.x86_64.rpm | 705 kB 00:00
--------------------------------------------------------------------------------
Total 5.6 MB/s | 75 MB 00:13
warning: rpmts_HdrFromFdno: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Retrieving key from file:/etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
Importing GPG key 0x5072E1F5:
Userid : MySQL Release Engineering
Package: mysql-community-release-el6-5.noarch (installed)
From : file:/etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
Is this ok [y/N]: y
warning: rpmts_HdrFromFdno: Header V3 RSA/SHA256 Signature, key ID c105b9de: NOKEY
Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
Importing GPG key 0xC105B9DE:
Userid : CentOS-6 Key (CentOS 6 Official Signing Key)
Package: centos-release-6-4.el6.centos.10.x86_64 (@anaconda-CentOS-201303020151.x86_64/6.4)
From : /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
Is this ok [y/N]: y
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
Warning: RPMDB altered outside of yum.
Installing : mysql-community-common-5.6.41-2.el6.x86_64 1/5
Installing : mysql-community-libs-5.6.41-2.el6.x86_64 2/5
Installing : mysql-community-client-5.6.41-2.el6.x86_64 3/5
Installing : perl-DBI-1.609-4.el6.x86_64 4/5
Installing : mysql-community-server-5.6.41-2.el6.x86_64 5/5
Verifying : mysql-community-server-5.6.41-2.el6.x86_64 1/5
Verifying : perl-DBI-1.609-4.el6.x86_64 2/5
Verifying : mysql-community-client-5.6.41-2.el6.x86_64 3/5
Verifying : mysql-community-libs-5.6.41-2.el6.x86_64 4/5
Verifying : mysql-community-common-5.6.41-2.el6.x86_64 5/5
Installed:
mysql-community-server.x86_64 0:5.6.41-2.el6
Dependency Installed:
mysql-community-client.x86_64 0:5.6.41-2.el6
mysql-community-common.x86_64 0:5.6.41-2.el6
mysql-community-libs.x86_64 0:5.6.41-2.el6
perl-DBI.x86_64 0:1.609-4.el6
Complete!
7.安装成功后
# service mysqld start
Initializing MySQL database: 2018-08-23 13:16:31 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2018-08-23 13:16:31 0 [Note] Ignoring --secure-file-priv value as server is running with --bootstrap.
2018-08-23 13:16:31 0 [Note] /usr/sbin/mysqld (mysqld 5.6.41) starting as process 3006 ...
2018-08-23 13:16:31 3006 [Note] InnoDB: Using atomics to ref count buffer pool pages
2018-08-23 13:16:31 3006 [Note] InnoDB: The InnoDB memory heap is disabled
2018-08-23 13:16:31 3006 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2018-08-23 13:16:31 3006 [Note] InnoDB: Memory barrier is not used
2018-08-23 13:16:31 3006 [Note] InnoDB: Compressed tables use zlib 1.2.3
2018-08-23 13:16:31 3006 [Note] InnoDB: Using Linux native AIO
2018-08-23 13:16:31 3006 [Note] InnoDB: Using CPU crc32 instructions
2018-08-23 13:16:31 3006 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2018-08-23 13:16:31 3006 [Note] InnoDB: Completed initialization of buffer pool
2018-08-23 13:16:31 3006 [Note] InnoDB: The first specified data file ./ibdata1 did not exist: a new database to be created!
2018-08-23 13:16:31 3006 [Note] InnoDB: Setting file ./ibdata1 size to 12 MB
2018-08-23 13:16:31 3006 [Note] InnoDB: Database physically writes the file full: wait...
2018-08-23 13:16:31 3006 [Note] InnoDB: Setting log file ./ib_logfile101 size to 48 MB
2018-08-23 13:16:31 3006 [Note] InnoDB: Setting log file ./ib_logfile1 size to 48 MB
2018-08-23 13:16:31 3006 [Note] InnoDB: Renaming log file ./ib_logfile101 to ./ib_logfile0
2018-08-23 13:16:31 3006 [Warning] InnoDB: New log files created, LSN=45781
2018-08-23 13:16:31 3006 [Note] InnoDB: Doublewrite buffer not found: creating new
2018-08-23 13:16:31 3006 [Note] InnoDB: Doublewrite buffer created
2018-08-23 13:16:31 3006 [Note] InnoDB: 128 rollback segment(s) are active.
2018-08-23 13:16:31 3006 [Warning] InnoDB: Creating foreign key constraint system tables.
2018-08-23 13:16:31 3006 [Note] InnoDB: Foreign key constraint system tables created
2018-08-23 13:16:31 3006 [Note] InnoDB: Creating tablespace and datafile system tables.
2018-08-23 13:16:31 3006 [Note] InnoDB: Tablespace and datafile system tables created.
2018-08-23 13:16:31 3006 [Note] InnoDB: Waiting for purge to start
2018-08-23 13:16:31 3006 [Note] InnoDB: 5.6.41 started; log sequence number 0
2018-08-23 13:16:31 3006 [Note] Binlog end
2018-08-23 13:16:31 3006 [Note] InnoDB: FTS optimize thread exiting.
2018-08-23 13:16:31 3006 [Note] InnoDB: Starting shutdown...
2018-08-23 13:16:33 3006 [Note] InnoDB: Shutdown completed; log sequence number 1625977
2018-08-23 13:16:33 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2018-08-23 13:16:33 0 [Note] Ignoring --secure-file-priv value as server is running with --bootstrap.
2018-08-23 13:16:33 0 [Note] /usr/sbin/mysqld (mysqld 5.6.41) starting as process 3028 ...
2018-08-23 13:16:33 3028 [Note] InnoDB: Using atomics to ref count buffer pool pages
2018-08-23 13:16:33 3028 [Note] InnoDB: The InnoDB memory heap is disabled
2018-08-23 13:16:33 3028 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2018-08-23 13:16:33 3028 [Note] InnoDB: Memory barrier is not used
2018-08-23 13:16:33 3028 [Note] InnoDB: Compressed tables use zlib 1.2.3
2018-08-23 13:16:33 3028 [Note] InnoDB: Using Linux native AIO
2018-08-23 13:16:33 3028 [Note] InnoDB: Using CPU crc32 instructions
2018-08-23 13:16:33 3028 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2018-08-23 13:16:33 3028 [Note] InnoDB: Completed initialization of buffer pool
2018-08-23 13:16:33 3028 [Note] InnoDB: Highest supported file format is Barracuda.
2018-08-23 13:16:33 3028 [Note] InnoDB: 128 rollback segment(s) are active.
2018-08-23 13:16:33 3028 [Note] InnoDB: Waiting for purge to start
2018-08-23 13:16:33 3028 [Note] InnoDB: 5.6.41 started; log sequence number 1625977
2018-08-23 13:16:33 3028 [Note] Binlog end
2018-08-23 13:16:33 3028 [Note] InnoDB: FTS optimize thread exiting.
2018-08-23 13:16:33 3028 [Note] InnoDB: Starting shutdown...
2018-08-23 13:16:35 3028 [Note] InnoDB: Shutdown completed; log sequence number 1625987
PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:
/usr/bin/mysqladmin -u root password 'new-password'
/usr/bin/mysqladmin -u root -h localhost.localdomain password 'new-password'
Alternatively you can run:
/usr/bin/mysql_secure_installation
which will also give you the option of removing the test
databases and anonymous user created by default. This is
strongly recommended for production servers.
See the manual for more instructions.
Please report any problems at http://bugs.mysql.com/
The latest information about MySQL is available on the web at
http://www.mysql.com
Support MySQL by buying support/licenses at http://shop.mysql.com
Note: new default config file not created.
Please make sure your config file is current
WARNING: Default config file /etc/my.cnf exists on the system
This file will be read by default by the MySQL server
If you do not want to use this, either remove it, or use the
--defaults-file argument to mysqld_safe when starting the server
[ OK ]
Starting mysqld: [ OK ]
8.由于mysql刚刚安装完的时候,mysql的root用户的密码默认是空的,所以我们需要及时用mysql的root用户登录
(第一次回车键,不用输入密码),并修改密码
# mysql -u root
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.6.41 MySQL Community Server (GPL)
Copyright (c) 2000, 2018, 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.
# use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
# update user set password=PASSWORD("这里输入root用户密码") where User='root';
Query OK, 4 rows affected (0.02 sec)
Rows matched: 4 Changed: 4 Warnings: 0
# flush privileges;
Query OK, 0 rows affected (0.02 sec)
9.查看mysql是否自启动,这里是在linux中执行的并且设置开启自启动命令
# chkconfig --list | grep mysqld
mysqld 0:off 1:off 2:off 3:on 4:on 5:on 6:off
10.设置开机启动
# chkconfig mysqld on
mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off
11.使用mysql -u root -p输入密码进入mysql,查看mysql编码
mysql> show variables like 'character%';
+--------------------------+----------------------------+
| Variable_name | Value |
+--------------------------+----------------------------+
| character_set_client | utf8 |
| character_set_connection | utf8 |
| character_set_database | latin1 |
| character_set_filesystem | binary |
| character_set_results | utf8 |
| character_set_server | latin1 |
| character_set_system | utf8 |
| character_sets_dir | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
8 rows in set (0.00 sec)
12.退出mysql,关闭mysql
mysql> exit
Bye
[root@localhost local]# service mysqld stop
13.修改vi /etc/my.cnf
[root@localhost local]# vi /etc/my.cnf
在文件中添加下面这段代码
[client]
default_character_set=utf8
[mysqld]
collation_server = utf8_general_ci
character_set_server = utf8
14.启动mysql
[root@localhost local]# service mysqld start
Starting mysqld: [ OK ]
15.进入mysql
[root@localhost local]# 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.6.41 MySQL Community Server (GPL)
Copyright (c) 2000, 2018, 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编码
mysql> show variables like 'character%';
亲测有效,
完美解决MySQL Access denied for user 'root'@'IP地址' 问题 解决远程链接
1、mysql -u root -p 登陆进MYSQL;
2、执行以下命令:
GRANT ALL PRIVILEGES ON *.* TO 'your name'@'%' IDENTIFIED BY 'your password' WITH GRANT OPTION;
数据库导入问题
1、首先建空数据库
mysql>create database dbname ;
2、导入数据库
方法一:
(1)选择数据库
mysql>use dbname ;
(2)设置数据库编码
mysql>set names utf8;
(3)导入数据(注意sql文件的路径)
mysql>source /home/xxxx/dbname.sql;
方法二:
mysql -u用户名 -p密码 数据库名 < 数据库名.sql
FLUSH PRIVILEGES;
grant all privileges on *.* to 'root'@'%' identified by 'luxing' with grant option;
flush privileges;
3、exit;
4、[root@localhost bin]# service mysqld restart
使用navicat链接linux的mysql数据库,测试可以连接