Mysql编译安装详解

时间:2022-06-16 05:18:50

wget http://mirrors.cnnic.cn/apache/httpd/mysql-5.5.20.tar.gz

root@Mysql-server ~]# yum install -y cmake ncurses-devel

[root@Mysql-server ~]# tar zxvf mysql-5.5.20.tar.gz -C /usr/src/

[root@Mysql-server ~]# cd /usr/src/mysql-5.5.20/
[root@Mysql-server mysql-5.5.20]# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DSYSCONFDIR=/etc/ -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci

root@Mysql-server mysql-5.5.20]# make

[root@Mysql-server mysql-5.5.20]# make install

[root@Mysql-server mysql-5.5.20]# useradd -M -s /sbin/nologin mysql
[root@Mysql-server mysql-5.5.20]# chown mysql:mysql /usr/local/mysql/
[root@Mysql-server mysql-5.5.20]# cp /usr/local/mysql/support-files/my-medium.cnf /etc/my.cnf

[root@Mysql-server mysql-5.5.20]# echo "PATH=$PATH:/usr/local/mysql/bin:" >> /etc/profile
[root@Mysql-server mysql-5.5.20]# source /etc/profile

[root@Mysql-server mysql-5.5.20]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
[root@Mysql-server mysql-5.5.20]# chmod +x /etc/init.d/mysqld

[root@Mysql-server mysql-5.5.20]# chkconfig --add mysqld

[root@Mysql-server mysql-5.5.20]# chkconfig mysqld on

[root@Mysql-server mysql-5.5.20]# /etc/init.d/mysqld start
Starting MySQL......... SUCCESS!
[root@Mysql-server mysql-5.5.20]# mysqladmin -u root password '123.com'

mysql> create database xiaoyudb;

mysql> use xiaoyudb;

mysql> mysql> create table test01 (id varchar(20),name varchar(20));

mysql> insert into test01 values("001","xiaoyu");
Query OK, 1 row affected (0.19 sec)

mysql> select * from test01;
+------+--------+
| id | name |
+------+--------+
| 001 | xiaoyu |
+------+--------+
1 row in set (0.01 sec)

mysql> create table test02 (id varchar(20),name varchar(20));
Query OK, 0 rows affected (1.00 sec)

mysql> insert into test02 values("002","zhangsan");     #在表中插入数据
Query OK, 1 row affected (0.61 sec)

mysql> desc test01;       # 查看表结构字段内容
+-------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| id | varchar(20) | YES | | NULL | |
| name | varchar(20) | YES | | NULL | |
+-------+-------------+------+-----+---------+-------+
2 rows in set (0.00 sec)

mysql> alter table test01 modify column name varchar(30);     #修改表中name字段的长度
Query OK, 1 row affected (0.05 sec)
Records: 1 Duplicates: 0 Warnings: 0

Mysql编译安装详解

mysql> update test01 set name='hexun.net' where id =1;  update test01 set name='hexun.net';   #修改表中某字段中的数据      
Query OK, 1 row affected (0.03 sec)
Rows matched: 1 Changed: 1 Warnings: 0

mysql> select * from test01;      #查看表中数据是否变动!
+------+-----------+
| id | name |
+------+-----------+
| 001 | hexun.net |
+------+-----------+
1 row in set (0.00 sec)

mysql> grant all on xiaoyudb.* to test@localhost identified by '123.com';      
Query OK, 0 rows affected (0.00 sec)

mysql> grant select,insert,update,delete on *.* to test@"%" identified by '123.com';  
Query OK, 0 rows affected (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

[root@Mysql-server mysql-5.5.20]# cd /usr/local/mysql/data/

[root@Mysql-server data]# mysqldump -uroot -p123.com xiaoyudb > /tmp/testyudb.sql

  • 修改Mysql字符集为UTF-8的方法:

在/etc/my.cnf对应如下配置段加入相应命令。

[client]字段里加入  default-character-set=utf8

[mysqld]字段里加入character-set-server=utf8

[mysql]字段里加入  default-character-set=utf8

mysql> show variables like 'collation_%';
+----------------------+-----------------+
| Variable_name | Value |
+----------------------+-----------------+
| collation_connection | utf8_general_ci |
| collation_database | utf8_general_ci |
| collation_server | utf8_general_ci |
+----------------------+-----------------+
3 rows in set (0.00 sec)

[root@Mysql-server tmp]# /usr/local/mysql/bin/mysqld_safe --user=mysql --skip-grant-tables &
[1] 11893
[root@Mysql-server tmp]# 170908 09:30:31 mysqld_safe Logging to '/usr/local/mysql/data/Mysql-server.err'.
170908 09:30:31 mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql/data

[root@Mysql-server tmp]# mysql

mysql> update user set password=password('123456') where user='root';
Query OK, 4 rows affected (0.00 sec)
Rows matched: 4 Changed: 4 Warnings: 0

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

启动mysql,输入已修改好的密码,重新登录即可

[root@Mysql-server tmp]# mysql -u root -p123456