linux 安装mysql

1.输入 yum -y install mysql-server

[root@iZ25rdhqcmhZ ~]# yum -y install mysql-server
Loaded plugins: security
base                                                                                                      | 3.7 kB     00:00     
base/primary_db                                                                                           | 4.6 MB     00:01     
epel                                                                                                      | 4.4 kB     00:00     
epel/primary_db                                                                                           | 6.5 MB     00:01     
extras                                                                                                    | 3.4 kB     00:00     
extras/primary_db                                                                                         |  30 kB     00:00     
updates                                                                                                   | 3.4 kB     00:00     
updates/primary_db                                                                                        | 3.2 MB     00:00     
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package mysql-server.x86_64 0:5.1.73-3.el6_5 will be installed
--> Processing Dependency: mysql = 5.1.73-3.el6_5 for package: mysql-server-5.1.73-3.el6_5.x86_64
--> Processing Dependency: perl-DBI for package: mysql-server-5.1.73-3.el6_5.x86_64
--> Processing Dependency: perl-DBD-MySQL for package: mysql-server-5.1.73-3.el6_5.x86_64
--> Processing Dependency: perl(DBI) for package: mysql-server-5.1.73-3.el6_5.x86_64
--> Running transaction check
---> Package mysql.x86_64 0:5.1.73-3.el6_5 will be installed
---> Package perl-DBD-MySQL.x86_64 0:4.013-3.el6 will be installed
---> Package perl-DBI.x86_64 0:1.609-4.el6 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

=================================================================================================================================
 Package                            Arch                       Version                            Repository                Size
=================================================================================================================================
Installing:
 mysql-server                       x86_64                     5.1.73-3.el6_5                     base                     8.6 M
Installing for dependencies:
 mysql                              x86_64                     5.1.73-3.el6_5                     base                     894 k
 perl-DBD-MySQL                     x86_64                     4.013-3.el6                        base                     134 k
 perl-DBI                           x86_64                     1.609-4.el6                        base                     705 k

Transaction Summary
=================================================================================================================================
Install       4 Package(s)

Total download size: 10 M
Installed size: 29 M
Downloading Packages:
(1/4): mysql-5.1.73-3.el6_5.x86_64.rpm                                                                    | 894 kB     00:00     
(2/4): mysql-server-5.1.73-3.el6_5.x86_64.rpm                                                             | 8.6 MB     00:01     
(3/4): perl-DBD-MySQL-4.013-3.el6.x86_64.rpm                                                              | 134 kB     00:00     
(4/4): perl-DBI-1.609-4.el6.x86_64.rpm                                                                    | 705 kB     00:00     
---------------------------------------------------------------------------------------------------------------------------------
Total                                                                                            4.5 MB/s |  10 MB     00:02     
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing : perl-DBI-1.609-4.el6.x86_64                                                                                   1/4
  Installing : perl-DBD-MySQL-4.013-3.el6.x86_64                                                                             2/4
  Installing : mysql-5.1.73-3.el6_5.x86_64                                                                                   3/4
  Installing : mysql-server-5.1.73-3.el6_5.x86_64                                                                            4/4
  Verifying  : perl-DBD-MySQL-4.013-3.el6.x86_64                                                                             1/4
  Verifying  : mysql-server-5.1.73-3.el6_5.x86_64                                                                            2/4
  Verifying  : mysql-5.1.73-3.el6_5.x86_64                                                                                   3/4
  Verifying  : perl-DBI-1.609-4.el6.x86_64                                                                                   4/4

Installed:
  mysql-server.x86_64 0:5.1.73-3.el6_5                                                                                           

Dependency Installed:
  mysql.x86_64 0:5.1.73-3.el6_5           perl-DBD-MySQL.x86_64 0:4.013-3.el6           perl-DBI.x86_64 0:1.609-4.el6          

Complete!

2.配置mysql字符集UTF-8

[root@iZ25rdhqcmhZ ~]# vim /etc/my.cnf

[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
# Default to using old password format for compatibility with mysql 3.x
# clients (those using the mysqlclient10 compatibility package).
old_passwords=1  ← 找到这一行,在这一行的下面添加新的规则,让MySQL的默认编码为UTF-8
default-character-set = utf8  ← 添加这一行
 
然后在配置文件的文尾填加如下语句:
 
[mysql]
default-character-set = utf8
3.启动MySQL和初始环境设定

[root@192 local]#chkconfig mysqld on ← 设置MySQL服务随系统启动自启动
 
[root@192 local]#chkconfig --list mysqld ← 确认MySQL自启动
mysqld          0:关闭  1:关闭  2:启用  3:启用  4:启用  5:启用  6:关闭
 
                                              ← 如果2--5为启用(或on)的状态就OK
 
[root@192 local]#/etc/rc.d/init.d/mysqld start  ← 启动MySQL服务

初始化 MySQL 数据库: Installing MySQL system tables...
OK
Filling help tables...
OK
 
To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system
 
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 192.168.0.1 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.
 
You can test the MySQL daemon with mysql-test-run.pl
cd mysql-test ; perl mysql-test-run.pl
 
Please report any problems with the /usr/bin/mysqlbug script!
 
The latest information about MySQL is available on the web at
http://www.mysql.com
Support MySQL by buying support/licenses athttp://shop.mysql.com   [确定]
启动 mysqld:                                              [确定]

4.MySQL初始环境设定
为MySQL的root用户设置密码
[root@192 local]#mysql -u root  ← 在没设置密码之时,用root用户登录MySQL服务器
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.0.95 Source distribution
 
Copyright (c) 2000, 2011, 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> select user,host,password from mysql.user;  ← 查看用户信息
mysql> select user,host,password from mysql.user;
+------+-------------+----------+
| user | host        | password |
+------+-------------+----------+
| root | localhost   |          | 
| root | 192.168.0.1 |          | 
| root | 127.0.0.1   |          | 
|      | localhost   |          | 
|      | 192.168.0.1 |          | 
+------+-------------+----------+
5 rows in set (0.03 sec)
 
mysql> set password forroot@localhost=password ('在这里填入root密码');  ← 设置root密码
 
譬如,在我的系统中,我是如下设置:
 
mysql> set password for root@localhost=password ('wangyun');
 
Query OK, 0 rows affected (0.01 sec)
 
mysql> set password for root@192.168.0.1=password ('wangyun');
Query OK, 0 rows affected (0.01 sec)
 
mysql> set password for root@127.0.0.1=password ('wangyun');
Query OK, 0 rows affected (0.01 sec)
 
 
 
mysql> select user,host,password from mysql.user;  ← 查看用户信息
 
+------+-------------+------------------+
| user | host        | password         |
+------+-------------+------------------+
| root | localhost   | 5f2dfe4b07af795b | 
| root | 192.168.0.1 | 5f2dfe4b07af795b | 
| root | 127.0.0.1   | 5f2dfe4b07af795b | 
|      | localhost   |                  | 
|      | 192.168.0.1 |                  | 
+------+-------------+------------------+
5 rows in set (0.01 sec)
 
mysql> exit  ← 退出MySQL服务器
Bye
 
 
 
  [2] 测试设置的root密码是否生效
 
 
 
[root@192 local]# mysql -u root      ← 通过空密码用root登录
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
                                     ← 出现此错误信息说明密码设置成功
 
[root@192 local]# mysql -u root-p    ← 通过密码用root登录
Enter password: ← 在这里输入密码
 
 
Welcome to the MySQL monitor.  Commands end with ; or \g.  ← 确认用密码能够成功登录
Your MySQL connection id is 5
Server version: 5.0.95 Source distribution
 
...  ...
 
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
 
[root@192 local]#mysql -u root -h 127.0.0.1 -p ← 通过密码用root登录
Enter password:   ← 在这里输入密码
Welcome to the MySQL monitor.  Commands end with ; or \g.← 确认用密码能够成功登录
Your MySQL connection id is 13
Server version: 5.0.95 Source distribution
 
......
 
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
 
mysql> exit  ← 退出MySQL服务器
[3] 删除匿名用户
 
 
 
在MySQL刚刚被安装后,存在用户名、密码为空的用户。这使得数据库服务器有无需密码被登录的可能性。为消除隐患,将匿名用户删除。
 
 
 
[root@192 local]# mysql -u root -p; ← 通过密码用root登录
Enter password:    ← 在这里输入密码
 
 
 
mysql> select user,host from mysql.user;
+------+-------------+
| user | host        |
+------+-------------+
| root | 127.0.0.1   | 
|      | 192.168.0.1 | 
| root | 192.168.0.1 | 
|      | localhost   | 
| root | localhost   | 
+------+-------------+
5 rows in set (0.03 sec)
 
 
 
mysql> delete from mysql.user where user=''; ← 删除匿名用户
 
Query OK, 2 rows affected (0.04 sec)
 
 
 
mysql> select user,host from mysql.user;  ← 查看用户信息
 
+------+-------------+
| user | host        |
+------+-------------+
| root | 127.0.0.1   | 
| root | 192.168.0.1 | 
| root | localhost   | 
+------+-------------+
3 rows in set (0.00 sec)
 
 
 
mysql> flush privileges;  ← 刷新,使以上操作生效
 
mysql> exit;   ←退出MySQL服务器
Bye
 
 
三.为linux配置%(其他的任何机器访问)
1.mysql -u root -p
2.输入密码
mysql>use mysql;
//添加用户,设置任何机器都可以访问
mysql>insert into mysql.user(Host,User,Password) values("%","localhost",password("***"));
更新所有的root用户密码都为你设置的 ***
mysql>update user set password=passworD("***") where user='root';
mysql>flush privileges;
--->让修改生效

 
   第四篇:日志位置和网络服务器 
 一、日志位置
 
mysql 默认的日志位置,mysql日志文件默认存放位置 /var/log/mysqld.log
 
[root@192 ~]# cd /var/log
[root@192 log]# pwd
/var/log
[root@192 log]# ls
acpid                  boot.log.2       conman.old  dmesg    maillog          messages.2    ppp             samba                setroubleshoot   tallylog
anaconda.log      boot.log.3        cron             faillog     maillog.1       messages.3   prelink        scrollkeeper.log   spooler              vbox
anaconda.syslog  boot.log.4        cron.1         gdm        maillog.2       messages.4   rpmpkgs      secure               spooler.1           wtmp
anaconda.xlog     brcm-iscsi.log  cron.2         httpd       maillog.3      mysqld.log     rpmpkgs.1    secure.1            spooler.2            xen
audit                   btmp               cron.3         lastlog     maillog.4      news             rpmpkgs.2    secure.2            spooler.3           Xorg.0.log
boot.log              clumond.log     cron.4         libvirt       messages     piranha          rpmpkgs.3   secure.3            spooler.4          Xorg.0.log.old
boot.log.1           conman           cups            mail         messages.1  pm                rpmpkgs.4    secure.4             squid                yum.log
 
 
 




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值