linux - yum 安装配置mysql

时间:2022-10-10 17:08:49

YUM查看可用安装包

[root@microlmj ~]# yum list mysql*

Available Packages
MySQL-python.x86_64 1.2.3-0.3.c1.1.el6 base
mysql.x86_64 5.1.73-3.el6_5 updates
mysql-bench.x86_64 5.1.73-3.el6_5 updates
mysql-connector-java.noarch 1:5.1.17-6.el6 base
mysql-connector-odbc.x86_64 5.1.5r1144-7.el6 base
mysql-devel.x86_64 5.1.73-3.el6_5 updates
mysql-embedded.x86_64 5.1.73-3.el6_5 updates
mysql-embedded-devel.x86_64 5.1.73-3.el6_5 updates
mysql-libs.x86_64 5.1.73-3.el6_5 updates
mysql-server.x86_64 5.1.73-3.el6_5 updates
mysql-test.x86_64 5.1.73-3.el6_5 updates

安装mysql,mysql-server,mysql-devel.

[root@microlmj~]# yum -y install mysql
[root@microlmj~]# yum -y install mysql-server
[root@microlmj~]# yum -y install mysql-devel
---Complete!
设置字符编码

[root@microlmj~]# vi /etc/my.cnf 
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0

[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

#new add
default-character-set=utf8

启动服务

[root@microlmj init.d]# /etc/rc.d/init.d/mysqld start
[ OK ]
Starting mysqld: [ OK ]
刚安装的mysql root 用户 是没有密码的 登录 自己设置密码

[root@microlmj init.d]# mysql -u root
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.1.73 Source distribution

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>
看一下用户列表
mysql> select user ,host, password from mysql.user;
+------+-----------------------+----------+
| user | host | password |
+------+-----------------------+----------+
| root | localhost | |
| root | ay14031710421034561bz | |
| root | 127.0.0.1 | |
| | localhost | |
| | ay14031710421034561bz | |
+------+-----------------------+----------+
5 rows in set (0.00 sec)
密码栏都是空的
给root@localhost设置一个密码

mysql> set password for root@localhost=password('yourpassword');
Query OK, 0 rows affected (0.00 sec)
再看一下用户表
mysql> select user ,host, password from mysql.user;
+------+-----------------------+-------------------------------------------+
| user | host | password |
+------+-----------------------+-------------------------------------------+
| root | localhost | *7E7C3D7567802A1EC617020149BB4B81E551B5EB |
| root | ay14031710421034561bz | |
| root | 127.0.0.1 | |
| | localhost | |
| | ay14031710421034561bz | |
+------+-----------------------+-------------------------------------------+
5 rows in set (0.00 sec)
退出再重新登录

mysql> exit
Bye
[root@microlmj init.d]# mysql -u root
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
需要密码了 -.-
输入密码登录 0>.<0
[root@microlmj init.d]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 7
Server version: 5.1.73 Source distribution
...
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>
本地的访问就没问题了 perhaps  -.-
但是俺想远程访问
新建个用户microlmj  (*用root账户登陆先)
mysql> insert into mysql.user(Host,User,Password) values("%","microlmj",password("microlmj"));
Host字段是 % 允许所有地址访问
刷新系统权限-.-

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
[root@microlmj init.d]# mysql -u microlmj -pEnter password: Welcome to the MySQL monitor.  Commands end with ; or \g....Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql>
用新建的用户登录 创建一个表试试

mysql> use test;
Database changed
mysql> show tables;
Empty set (0.00 sec)

mysql> create table user (id int primary key, name varchar(10));
Query OK, 0 rows affected (0.01 sec)

mysql> desc user;
+-------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| id | int(11) | NO | PRI | NULL | |
| name | varchar(10) | YES | | NULL | |
+-------+-------------+------+-----+---------+-------+
2 rows in set (0.00 sec)
好吧,用navicat测试一下远程访问行不行 -.-

linux - yum 安装配置mysql

linux - yum 安装配置mysql
连接成功 -.-
Complete!
-.-