mysql解除安裝
yum remove mysql mysql-server mysql-libs compat-mysql51
rm -rf /var/lib/mysql
rm /etc/my.cnf
檢視是否還有mysql軟體:
rpm -qa|grep mysql
有的話繼續删除
mysql安裝
1>若本地沒有安裝包 可以考慮使用yum指令進行下載下傳
# yum -y install mysql-server
# yum -y install php-mysql
2>安裝後,mysql自動啟動,預設沒有使用者名和密碼,設定新密碼
# /usr/bin/mysqladmin -u root password 'aaaaaa'
[root@luozhonghua ~]# /usr/bin/mysqladmin -u root password 'aaaaaa'
/usr/bin/mysqladmin: connect to server at 'localhost' failed
error: 'can't connect to local mysql server through socket '/var/lib/mysql/mysql.sock' (2)'
check that mysqld is running and that the socket: '/var/lib/mysql/mysql.sock' exists!
解決:
2.1》/etc/rc.d/init.d/mysqld status 看看mysql是否已經啟動
3.2》service mysqld start
3>登入mysql
>mysql -u root -p
enter password:’aaaaaa’
4>賦權連接配接的主機
#grant select,insert,update,delete on *.* to [email protected] identified by 'aaaaaa'
grant select,insert,update,delete on *.* to [email protected] identified by 'aaaaaa';
5>更改預設字元集
# cp my-medium.cnf /etc/my.cnf
在[client]下加入 default-character-set=utf8
在[mysqld]下加入 default-character-set=utf8
查找安裝路徑
rpm -qa | grep mysql
rpm -ql 包名
[root@luozhonghua charsets]# find /usr -name my-medium.cnf
/usr/share/doc/mysql-server-5.1.73/my-medium.cnf
/usr/share/mysql/my-medium.cnf
#6>設定mysql開機自啟動
# vi /etc/rc.local
加入如下一行
#/usr/share/mysql/mysql.server start
7>重新啟動mysql
# /etc/init.d/mysql restart
service mysqld restart
8>測試;
[root@luozhonghua ~]# mysql -u root -p
enter password:
welcome to the mysql monitor. commands end with ; or \g.
your mysql connection id is 3
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> create database xxx
-> ;
query ok, 1 row affected (0.06 sec)
mysql> ls
error 1064 (42000): you have an error in your sql syntax; check the manual th at corresponds to your mysql server version for the right syntax to use near
'ls' at line 1
mysql> show databases
+--------------------+
| database |
| information_schema |
| mysql |
| test |
| xxx |
4 rows in set (0.06 sec)
mysql> use xxx;
database changed
mysql> show database
'database' at line 1
mysql> show databases;
4 rows in set (0.01 sec)
mysql> create table test(
-> int id not null,
-> varchar(20) name null);
'int id not null,
varchar(20) name null)' at line 2
mysql> show tables;
empty set (0.00 sec)
mysql> create table dbtest (
-> id int ,
-> name varchar);
')' at line 3
-> id int,
-> name varchar(10));
query ok, 0 rows affected (0.07 sec)
+---------------+
| tables_in_xxx |
| dbtest |
1 row in set (0.01 sec)
mysql> drop table xxx;
error 1051 (42s02): unknown table 'xxx'
mysql> drop table dbtest;
query ok, 0 rows affected (0.00 sec)
mysql>