linux 安装 mysql

1.用yum安装

yum install mysql-server
#yum -y install php-mysql

2.修改密码

vim /etc/my.cnf 
[mysqld]
在这里添加如下:设置默认为utf8
default-character-set = utf8

然后在配置文件的文尾填加如下语句:
[mysql]
default-character-set = utf8

 3.启动MySQL服务

设置MySQL服务随系统启动自启动
[root@fangsh ~]# chkconfig mysqld on 
确认一下MySQL自启动
[root@fangsh ~]# chkconfig --list mysqld 
mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off  (如果2--5为on的状态就是可以的)
启动MySQL服务
[root@sample ~]#service mysqld start 

Initializing MySQL database:         [ OK ]
Starting MySQL:                 [ OK ]

启动服务后, 有一个提示你修改密码。当然可以不用密码。


--------------------------------------------------------------------------

4. 登录

MySQL在刚刚被安装后如果root用户是没有被设置密码的。可用如下登录

[root@fangsh ~]# mysql -u root  (用root用户登录MySQL服务器)

如果有设置密码可用
[root@fangsh ~]# mysql -u root -p (然后再僌密码)

Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2 to server version: 4.1.20

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
最后可以用如下查看用户信息, 当然密码是加密后的。
mysql> select user,host,password from mysql.user; 

这种方式确实很初学者,我刚才接触linux mysql时,就是这么做过。现在基本都用 linux 下 mysql 安装(不用编译的方式)

--end

原文地址:https://www.cnblogs.com/fangshenghui/p/3099801.html